Skip to content

Commit

Permalink
Merge tag 'remoteproc-4.2' of git://git.kernel.org/pub/scm/linux/kern…
Browse files Browse the repository at this point in the history
…el/git/ohad/remoteproc

Pull remoteproc updates from Ohad Ben-Cohen:

 - remoteproc fixes/cleanups from Suman Anna

 - new remoteproc TI Wakeup M3 driver from Dave Gerlach

 - remoteproc core support for TI's Wakeup M3 driver from both Dave and Suman

 - tiny remoteproc build fix from myself

* tag 'remoteproc-4.2' of git://git.kernel.org/pub/scm/linux/kernel/git/ohad/remoteproc:
  remoteproc: fix !CONFIG_OF build breakage
  remoteproc/wkup_m3: add a remoteproc driver for TI Wakeup M3
  Documentation: dt: add bindings for TI Wakeup M3 processor
  remoteproc: add a rproc ops for performing address translation
  remoteproc: introduce rproc_get_by_phandle API
  remoteproc: fix various checkpatch warnings
  remoteproc/davinci: fix quoted split string checkpatch warning
  remoteproc/ste: add blank lines after declarations
  • Loading branch information
Linus Torvalds committed Jul 3, 2015
2 parents d033ed9 + 8de3dbd commit 2fee94b
Show file tree
Hide file tree
Showing 11 changed files with 460 additions and 32 deletions.
52 changes: 52 additions & 0 deletions Documentation/devicetree/bindings/remoteproc/wkup_m3_rproc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
TI Wakeup M3 Remoteproc Driver
==============================

The TI AM33xx and AM43xx family of devices use a small Cortex M3 co-processor
(commonly referred to as Wakeup M3 or CM3) to help with various low power tasks
that cannot be controlled from the MPU. This CM3 processor requires a firmware
binary to accomplish this. The wkup_m3 remoteproc driver handles the loading of
the firmware and booting of the CM3.

Wkup M3 Device Node:
====================
A wkup_m3 device node is used to represent the Wakeup M3 processor instance
within the SoC. It is added as a child node of the parent interconnect bus
(l4_wkup) through which it is accessible to the MPU.

Required properties:
--------------------
- compatible: Should be one of,
"ti,am3352-wkup-m3" for AM33xx SoCs
"ti,am4372-wkup-m3" for AM43xx SoCs
- reg: Should contain the address ranges for the two internal
memory regions, UMEM and DMEM. The parent node should
provide an appropriate ranges property for properly
translating these into bus addresses.
- reg-names: Contains the corresponding names for the two memory
regions. These should be named "umem" & "dmem".
- ti,hwmods: Name of the hwmod associated with the wkupm3 device.
- ti,pm-firmware: Name of firmware file to be used for loading and
booting the wkup_m3 remote processor.

Example:
--------
/* AM33xx */
ocp {
l4_wkup: l4_wkup@44c00000 {
compatible = "am335-l4-wkup", "simple-bus";
ranges = <0 0x44c00000 0x400000>;
#address-cells = <1>;
#size-cells = <1>;

wkup_m3: wkup_m3@100000 {
compatible = "ti,am3352-wkup-m3";
reg = <0x100000 0x4000>,
<0x180000 0x2000>;
reg-names = "umem", "dmem";
ti,hwmods = "wkup_m3";
ti,pm-firmware = "am335x-pm-firmware.elf";
};
};

...
};
6 changes: 6 additions & 0 deletions Documentation/remoteproc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ cost.
rproc_shutdown() returns, and users can still use it with a subsequent
rproc_boot(), if needed.

struct rproc *rproc_get_by_phandle(phandle phandle)
- Find an rproc handle using a device tree phandle. Returns the rproc
handle on success, and NULL on failure. This function increments
the remote processor's refcount, so always use rproc_put() to
decrement it back once rproc isn't needed anymore.

3. Typical usage

#include <linux/remoteproc.h>
Expand Down
13 changes: 13 additions & 0 deletions drivers/remoteproc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ config STE_MODEM_RPROC
This can be either built-in or a loadable module.
If unsure say N.

config WKUP_M3_RPROC
tristate "AMx3xx Wakeup M3 remoteproc support"
depends on SOC_AM33XX || SOC_AM43XX
select REMOTEPROC
help
Say y here to support Wakeup M3 remote processor on TI AM33xx
and AM43xx family of SoCs.

Required for Suspend-to-RAM on AM33xx and AM43xx SoCs. Also needed
for deep CPUIdle states on AM33xx SoCs. Allows for loading of the
firmware onto these remote processors.
If unsure say N.

config DA8XX_REMOTEPROC
tristate "DA8xx/OMAP-L13x remoteproc support"
depends on ARCH_DAVINCI_DA8XX
Expand Down
1 change: 1 addition & 0 deletions drivers/remoteproc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ remoteproc-y += remoteproc_virtio.o
remoteproc-y += remoteproc_elf_loader.o
obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o
obj-$(CONFIG_STE_MODEM_RPROC) += ste_modem_rproc.o
obj-$(CONFIG_WKUP_M3_RPROC) += wkup_m3_rproc.o
obj-$(CONFIG_DA8XX_REMOTEPROC) += da8xx_remoteproc.o
3 changes: 1 addition & 2 deletions drivers/remoteproc/da8xx_remoteproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
static char *da8xx_fw_name;
module_param(da8xx_fw_name, charp, S_IRUGO);
MODULE_PARM_DESC(da8xx_fw_name,
"\n\t\tName of DSP firmware file in /lib/firmware"
" (if not specified defaults to 'rproc-dsp-fw')");
"Name of DSP firmware file in /lib/firmware (if not specified defaults to 'rproc-dsp-fw')");

/*
* OMAP-L138 Technical References:
Expand Down
115 changes: 91 additions & 24 deletions drivers/remoteproc/remoteproc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

#include "remoteproc_internal.h"

static DEFINE_MUTEX(rproc_list_mutex);
static LIST_HEAD(rproc_list);

typedef int (*rproc_handle_resources_t)(struct rproc *rproc,
struct resource_table *table, int len);
typedef int (*rproc_handle_resource_t)(struct rproc *rproc,
Expand Down Expand Up @@ -132,32 +135,48 @@ static void rproc_disable_iommu(struct rproc *rproc)

iommu_detach_device(domain, dev);
iommu_domain_free(domain);

return;
}

/*
/**
* rproc_da_to_va() - lookup the kernel virtual address for a remoteproc address
* @rproc: handle of a remote processor
* @da: remoteproc device address to translate
* @len: length of the memory region @da is pointing to
*
* Some remote processors will ask us to allocate them physically contiguous
* memory regions (which we call "carveouts"), and map them to specific
* device addresses (which are hardcoded in the firmware).
* device addresses (which are hardcoded in the firmware). They may also have
* dedicated memory regions internal to the processors, and use them either
* exclusively or alongside carveouts.
*
* They may then ask us to copy objects into specific device addresses (e.g.
* code/data sections) or expose us certain symbols in other device address
* (e.g. their trace buffer).
*
* This function is an internal helper with which we can go over the allocated
* carveouts and translate specific device address to kernel virtual addresses
* so we can access the referenced memory.
* This function is a helper function with which we can go over the allocated
* carveouts and translate specific device addresses to kernel virtual addresses
* so we can access the referenced memory. This function also allows to perform
* translations on the internal remoteproc memory regions through a platform
* implementation specific da_to_va ops, if present.
*
* The function returns a valid kernel address on success or NULL on failure.
*
* Note: phys_to_virt(iommu_iova_to_phys(rproc->domain, da)) will work too,
* but only on kernel direct mapped RAM memory. Instead, we're just using
* here the output of the DMA API, which should be more correct.
* here the output of the DMA API for the carveouts, which should be more
* correct.
*/
void *rproc_da_to_va(struct rproc *rproc, u64 da, int len)
{
struct rproc_mem_entry *carveout;
void *ptr = NULL;

if (rproc->ops->da_to_va) {
ptr = rproc->ops->da_to_va(rproc, da, len);
if (ptr)
goto out;
}

list_for_each_entry(carveout, &rproc->carveouts, node) {
int offset = da - carveout->da;

Expand All @@ -174,6 +193,7 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, int len)
break;
}

out:
return ptr;
}
EXPORT_SYMBOL(rproc_da_to_va);
Expand Down Expand Up @@ -411,10 +431,8 @@ static int rproc_handle_trace(struct rproc *rproc, struct fw_rsc_trace *rsc,
}

trace = kzalloc(sizeof(*trace), GFP_KERNEL);
if (!trace) {
dev_err(dev, "kzalloc trace failed\n");
if (!trace)
return -ENOMEM;
}

/* set the trace buffer dma properties */
trace->len = rsc->len;
Expand Down Expand Up @@ -489,10 +507,8 @@ static int rproc_handle_devmem(struct rproc *rproc, struct fw_rsc_devmem *rsc,
}

mapping = kzalloc(sizeof(*mapping), GFP_KERNEL);
if (!mapping) {
dev_err(dev, "kzalloc mapping failed\n");
if (!mapping)
return -ENOMEM;
}

ret = iommu_map(rproc->domain, rsc->da, rsc->pa, rsc->len, rsc->flags);
if (ret) {
Expand Down Expand Up @@ -565,10 +581,8 @@ static int rproc_handle_carveout(struct rproc *rproc,
rsc->da, rsc->pa, rsc->len, rsc->flags);

carveout = kzalloc(sizeof(*carveout), GFP_KERNEL);
if (!carveout) {
dev_err(dev, "kzalloc carveout failed\n");
if (!carveout)
return -ENOMEM;
}

va = dma_alloc_coherent(dev->parent, rsc->len, &dma, GFP_KERNEL);
if (!va) {
Expand Down Expand Up @@ -768,7 +782,8 @@ static void rproc_resource_cleanup(struct rproc *rproc)

/* clean up carveout allocations */
list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) {
dma_free_coherent(dev->parent, entry->len, entry->va, entry->dma);
dma_free_coherent(dev->parent, entry->len, entry->va,
entry->dma);
list_del(&entry->node);
kfree(entry);
}
Expand Down Expand Up @@ -808,9 +823,8 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)

/* look for the resource table */
table = rproc_find_rsc_table(rproc, fw, &tablesz);
if (!table) {
if (!table)
goto clean_up;
}

/* Verify that resource table in loaded fw is unchanged */
if (rproc->table_csum != crc32(0, table, tablesz)) {
Expand Down Expand Up @@ -911,7 +925,8 @@ static void rproc_fw_config_virtio(const struct firmware *fw, void *context)

/* count the number of notify-ids */
rproc->max_notifyid = -1;
ret = rproc_handle_resources(rproc, tablesz, rproc_count_vrings_handler);
ret = rproc_handle_resources(rproc, tablesz,
rproc_count_vrings_handler);
if (ret)
goto out;

Expand Down Expand Up @@ -1151,6 +1166,50 @@ void rproc_shutdown(struct rproc *rproc)
}
EXPORT_SYMBOL(rproc_shutdown);

/**
* rproc_get_by_phandle() - find a remote processor by phandle
* @phandle: phandle to the rproc
*
* Finds an rproc handle using the remote processor's phandle, and then
* return a handle to the rproc.
*
* This function increments the remote processor's refcount, so always
* use rproc_put() to decrement it back once rproc isn't needed anymore.
*
* Returns the rproc handle on success, and NULL on failure.
*/
#ifdef CONFIG_OF
struct rproc *rproc_get_by_phandle(phandle phandle)
{
struct rproc *rproc = NULL, *r;
struct device_node *np;

np = of_find_node_by_phandle(phandle);
if (!np)
return NULL;

mutex_lock(&rproc_list_mutex);
list_for_each_entry(r, &rproc_list, node) {
if (r->dev.parent && r->dev.parent->of_node == np) {
rproc = r;
get_device(&rproc->dev);
break;
}
}
mutex_unlock(&rproc_list_mutex);

of_node_put(np);

return rproc;
}
#else
struct rproc *rproc_get_by_phandle(phandle phandle)
{
return NULL;
}
#endif
EXPORT_SYMBOL(rproc_get_by_phandle);

/**
* rproc_add() - register a remote processor
* @rproc: the remote processor handle to register
Expand Down Expand Up @@ -1180,6 +1239,11 @@ int rproc_add(struct rproc *rproc)
if (ret < 0)
return ret;

/* expose to rproc_get_by_phandle users */
mutex_lock(&rproc_list_mutex);
list_add(&rproc->node, &rproc_list);
mutex_unlock(&rproc_list_mutex);

dev_info(dev, "%s is available\n", rproc->name);

dev_info(dev, "Note: remoteproc is still under development and considered experimental.\n");
Expand Down Expand Up @@ -1268,10 +1332,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
name_len = strlen(name) + strlen(template) - 2 + 1;

rproc = kzalloc(sizeof(struct rproc) + len + name_len, GFP_KERNEL);
if (!rproc) {
dev_err(dev, "%s: kzalloc failed\n", __func__);
if (!rproc)
return NULL;
}

if (!firmware) {
p = (char *)rproc + sizeof(struct rproc) + len;
Expand Down Expand Up @@ -1369,6 +1431,11 @@ int rproc_del(struct rproc *rproc)
/* Free the copy of the resource table */
kfree(rproc->cached_table);

/* the rproc is downref'ed as soon as it's removed from the klist */
mutex_lock(&rproc_list_mutex);
list_del(&rproc->node);
mutex_unlock(&rproc_list_mutex);

device_del(&rproc->dev);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion drivers/remoteproc/remoteproc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct rproc;
* @get_boot_addr: get boot address to entry point specified in firmware
*/
struct rproc_fw_ops {
struct resource_table *(*find_rsc_table) (struct rproc *rproc,
struct resource_table *(*find_rsc_table)(struct rproc *rproc,
const struct firmware *fw,
int *tablesz);
struct resource_table *(*find_loaded_rsc_table)(struct rproc *rproc,
Expand Down
4 changes: 2 additions & 2 deletions drivers/remoteproc/ste_modem_rproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ static int sproc_load_segments(struct rproc *rproc, const struct firmware *fw)
static const struct ste_toc_entry *sproc_find_rsc_entry(const void *data)
{
int i;
const struct ste_toc *toc;
toc = data;
const struct ste_toc *toc = data;

/* Search the table for the resource table */
for (i = 0; i < SPROC_MAX_TOC_ENTRIES &&
Expand Down Expand Up @@ -230,6 +229,7 @@ static int sproc_start(struct rproc *rproc)
static int sproc_stop(struct rproc *rproc)
{
struct sproc *sproc = rproc->priv;

sproc_dbg(sproc, "stop ste-modem\n");

return sproc->mdev->ops.power(sproc->mdev, false);
Expand Down
Loading

0 comments on commit 2fee94b

Please sign in to comment.