Skip to content

Commit 2fee94b

Browse files
committed
Merge tag 'remoteproc-4.2' of git://git.kernel.org/pub/scm/linux/kernel/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
2 parents d033ed9 + 8de3dbd commit 2fee94b

11 files changed

Lines changed: 460 additions & 32 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
TI Wakeup M3 Remoteproc Driver
2+
==============================
3+
4+
The TI AM33xx and AM43xx family of devices use a small Cortex M3 co-processor
5+
(commonly referred to as Wakeup M3 or CM3) to help with various low power tasks
6+
that cannot be controlled from the MPU. This CM3 processor requires a firmware
7+
binary to accomplish this. The wkup_m3 remoteproc driver handles the loading of
8+
the firmware and booting of the CM3.
9+
10+
Wkup M3 Device Node:
11+
====================
12+
A wkup_m3 device node is used to represent the Wakeup M3 processor instance
13+
within the SoC. It is added as a child node of the parent interconnect bus
14+
(l4_wkup) through which it is accessible to the MPU.
15+
16+
Required properties:
17+
--------------------
18+
- compatible: Should be one of,
19+
"ti,am3352-wkup-m3" for AM33xx SoCs
20+
"ti,am4372-wkup-m3" for AM43xx SoCs
21+
- reg: Should contain the address ranges for the two internal
22+
memory regions, UMEM and DMEM. The parent node should
23+
provide an appropriate ranges property for properly
24+
translating these into bus addresses.
25+
- reg-names: Contains the corresponding names for the two memory
26+
regions. These should be named "umem" & "dmem".
27+
- ti,hwmods: Name of the hwmod associated with the wkupm3 device.
28+
- ti,pm-firmware: Name of firmware file to be used for loading and
29+
booting the wkup_m3 remote processor.
30+
31+
Example:
32+
--------
33+
/* AM33xx */
34+
ocp {
35+
l4_wkup: l4_wkup@44c00000 {
36+
compatible = "am335-l4-wkup", "simple-bus";
37+
ranges = <0 0x44c00000 0x400000>;
38+
#address-cells = <1>;
39+
#size-cells = <1>;
40+
41+
wkup_m3: wkup_m3@100000 {
42+
compatible = "ti,am3352-wkup-m3";
43+
reg = <0x100000 0x4000>,
44+
<0x180000 0x2000>;
45+
reg-names = "umem", "dmem";
46+
ti,hwmods = "wkup_m3";
47+
ti,pm-firmware = "am335x-pm-firmware.elf";
48+
};
49+
};
50+
51+
...
52+
};

‎Documentation/remoteproc.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ cost.
5151
rproc_shutdown() returns, and users can still use it with a subsequent
5252
rproc_boot(), if needed.
5353

54+
struct rproc *rproc_get_by_phandle(phandle phandle)
55+
- Find an rproc handle using a device tree phandle. Returns the rproc
56+
handle on success, and NULL on failure. This function increments
57+
the remote processor's refcount, so always use rproc_put() to
58+
decrement it back once rproc isn't needed anymore.
59+
5460
3. Typical usage
5561

5662
#include <linux/remoteproc.h>

‎drivers/remoteproc/Kconfig‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ config STE_MODEM_RPROC
4141
This can be either built-in or a loadable module.
4242
If unsure say N.
4343

44+
config WKUP_M3_RPROC
45+
tristate "AMx3xx Wakeup M3 remoteproc support"
46+
depends on SOC_AM33XX || SOC_AM43XX
47+
select REMOTEPROC
48+
help
49+
Say y here to support Wakeup M3 remote processor on TI AM33xx
50+
and AM43xx family of SoCs.
51+
52+
Required for Suspend-to-RAM on AM33xx and AM43xx SoCs. Also needed
53+
for deep CPUIdle states on AM33xx SoCs. Allows for loading of the
54+
firmware onto these remote processors.
55+
If unsure say N.
56+
4457
config DA8XX_REMOTEPROC
4558
tristate "DA8xx/OMAP-L13x remoteproc support"
4659
depends on ARCH_DAVINCI_DA8XX

‎drivers/remoteproc/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ remoteproc-y += remoteproc_virtio.o
99
remoteproc-y += remoteproc_elf_loader.o
1010
obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o
1111
obj-$(CONFIG_STE_MODEM_RPROC) += ste_modem_rproc.o
12+
obj-$(CONFIG_WKUP_M3_RPROC) += wkup_m3_rproc.o
1213
obj-$(CONFIG_DA8XX_REMOTEPROC) += da8xx_remoteproc.o

‎drivers/remoteproc/da8xx_remoteproc.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
static char *da8xx_fw_name;
2727
module_param(da8xx_fw_name, charp, S_IRUGO);
2828
MODULE_PARM_DESC(da8xx_fw_name,
29-
"\n\t\tName of DSP firmware file in /lib/firmware"
30-
" (if not specified defaults to 'rproc-dsp-fw')");
29+
"Name of DSP firmware file in /lib/firmware (if not specified defaults to 'rproc-dsp-fw')");
3130

3231
/*
3332
* OMAP-L138 Technical References:

‎drivers/remoteproc/remoteproc_core.c‎

Lines changed: 91 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444

4545
#include "remoteproc_internal.h"
4646

47+
static DEFINE_MUTEX(rproc_list_mutex);
48+
static LIST_HEAD(rproc_list);
49+
4750
typedef int (*rproc_handle_resources_t)(struct rproc *rproc,
4851
struct resource_table *table, int len);
4952
typedef int (*rproc_handle_resource_t)(struct rproc *rproc,
@@ -132,32 +135,48 @@ static void rproc_disable_iommu(struct rproc *rproc)
132135

133136
iommu_detach_device(domain, dev);
134137
iommu_domain_free(domain);
135-
136-
return;
137138
}
138139

139-
/*
140+
/**
141+
* rproc_da_to_va() - lookup the kernel virtual address for a remoteproc address
142+
* @rproc: handle of a remote processor
143+
* @da: remoteproc device address to translate
144+
* @len: length of the memory region @da is pointing to
145+
*
140146
* Some remote processors will ask us to allocate them physically contiguous
141147
* memory regions (which we call "carveouts"), and map them to specific
142-
* device addresses (which are hardcoded in the firmware).
148+
* device addresses (which are hardcoded in the firmware). They may also have
149+
* dedicated memory regions internal to the processors, and use them either
150+
* exclusively or alongside carveouts.
143151
*
144152
* They may then ask us to copy objects into specific device addresses (e.g.
145153
* code/data sections) or expose us certain symbols in other device address
146154
* (e.g. their trace buffer).
147155
*
148-
* This function is an internal helper with which we can go over the allocated
149-
* carveouts and translate specific device address to kernel virtual addresses
150-
* so we can access the referenced memory.
156+
* This function is a helper function with which we can go over the allocated
157+
* carveouts and translate specific device addresses to kernel virtual addresses
158+
* so we can access the referenced memory. This function also allows to perform
159+
* translations on the internal remoteproc memory regions through a platform
160+
* implementation specific da_to_va ops, if present.
161+
*
162+
* The function returns a valid kernel address on success or NULL on failure.
151163
*
152164
* Note: phys_to_virt(iommu_iova_to_phys(rproc->domain, da)) will work too,
153165
* but only on kernel direct mapped RAM memory. Instead, we're just using
154-
* here the output of the DMA API, which should be more correct.
166+
* here the output of the DMA API for the carveouts, which should be more
167+
* correct.
155168
*/
156169
void *rproc_da_to_va(struct rproc *rproc, u64 da, int len)
157170
{
158171
struct rproc_mem_entry *carveout;
159172
void *ptr = NULL;
160173

174+
if (rproc->ops->da_to_va) {
175+
ptr = rproc->ops->da_to_va(rproc, da, len);
176+
if (ptr)
177+
goto out;
178+
}
179+
161180
list_for_each_entry(carveout, &rproc->carveouts, node) {
162181
int offset = da - carveout->da;
163182

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

196+
out:
177197
return ptr;
178198
}
179199
EXPORT_SYMBOL(rproc_da_to_va);
@@ -411,10 +431,8 @@ static int rproc_handle_trace(struct rproc *rproc, struct fw_rsc_trace *rsc,
411431
}
412432

413433
trace = kzalloc(sizeof(*trace), GFP_KERNEL);
414-
if (!trace) {
415-
dev_err(dev, "kzalloc trace failed\n");
434+
if (!trace)
416435
return -ENOMEM;
417-
}
418436

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

491509
mapping = kzalloc(sizeof(*mapping), GFP_KERNEL);
492-
if (!mapping) {
493-
dev_err(dev, "kzalloc mapping failed\n");
510+
if (!mapping)
494511
return -ENOMEM;
495-
}
496512

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

567583
carveout = kzalloc(sizeof(*carveout), GFP_KERNEL);
568-
if (!carveout) {
569-
dev_err(dev, "kzalloc carveout failed\n");
584+
if (!carveout)
570585
return -ENOMEM;
571-
}
572586

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

769783
/* clean up carveout allocations */
770784
list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) {
771-
dma_free_coherent(dev->parent, entry->len, entry->va, entry->dma);
785+
dma_free_coherent(dev->parent, entry->len, entry->va,
786+
entry->dma);
772787
list_del(&entry->node);
773788
kfree(entry);
774789
}
@@ -808,9 +823,8 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
808823

809824
/* look for the resource table */
810825
table = rproc_find_rsc_table(rproc, fw, &tablesz);
811-
if (!table) {
826+
if (!table)
812827
goto clean_up;
813-
}
814828

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

912926
/* count the number of notify-ids */
913927
rproc->max_notifyid = -1;
914-
ret = rproc_handle_resources(rproc, tablesz, rproc_count_vrings_handler);
928+
ret = rproc_handle_resources(rproc, tablesz,
929+
rproc_count_vrings_handler);
915930
if (ret)
916931
goto out;
917932

@@ -1151,6 +1166,50 @@ void rproc_shutdown(struct rproc *rproc)
11511166
}
11521167
EXPORT_SYMBOL(rproc_shutdown);
11531168

1169+
/**
1170+
* rproc_get_by_phandle() - find a remote processor by phandle
1171+
* @phandle: phandle to the rproc
1172+
*
1173+
* Finds an rproc handle using the remote processor's phandle, and then
1174+
* return a handle to the rproc.
1175+
*
1176+
* This function increments the remote processor's refcount, so always
1177+
* use rproc_put() to decrement it back once rproc isn't needed anymore.
1178+
*
1179+
* Returns the rproc handle on success, and NULL on failure.
1180+
*/
1181+
#ifdef CONFIG_OF
1182+
struct rproc *rproc_get_by_phandle(phandle phandle)
1183+
{
1184+
struct rproc *rproc = NULL, *r;
1185+
struct device_node *np;
1186+
1187+
np = of_find_node_by_phandle(phandle);
1188+
if (!np)
1189+
return NULL;
1190+
1191+
mutex_lock(&rproc_list_mutex);
1192+
list_for_each_entry(r, &rproc_list, node) {
1193+
if (r->dev.parent && r->dev.parent->of_node == np) {
1194+
rproc = r;
1195+
get_device(&rproc->dev);
1196+
break;
1197+
}
1198+
}
1199+
mutex_unlock(&rproc_list_mutex);
1200+
1201+
of_node_put(np);
1202+
1203+
return rproc;
1204+
}
1205+
#else
1206+
struct rproc *rproc_get_by_phandle(phandle phandle)
1207+
{
1208+
return NULL;
1209+
}
1210+
#endif
1211+
EXPORT_SYMBOL(rproc_get_by_phandle);
1212+
11541213
/**
11551214
* rproc_add() - register a remote processor
11561215
* @rproc: the remote processor handle to register
@@ -1180,6 +1239,11 @@ int rproc_add(struct rproc *rproc)
11801239
if (ret < 0)
11811240
return ret;
11821241

1242+
/* expose to rproc_get_by_phandle users */
1243+
mutex_lock(&rproc_list_mutex);
1244+
list_add(&rproc->node, &rproc_list);
1245+
mutex_unlock(&rproc_list_mutex);
1246+
11831247
dev_info(dev, "%s is available\n", rproc->name);
11841248

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

12701334
rproc = kzalloc(sizeof(struct rproc) + len + name_len, GFP_KERNEL);
1271-
if (!rproc) {
1272-
dev_err(dev, "%s: kzalloc failed\n", __func__);
1335+
if (!rproc)
12731336
return NULL;
1274-
}
12751337

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

1434+
/* the rproc is downref'ed as soon as it's removed from the klist */
1435+
mutex_lock(&rproc_list_mutex);
1436+
list_del(&rproc->node);
1437+
mutex_unlock(&rproc_list_mutex);
1438+
13721439
device_del(&rproc->dev);
13731440

13741441
return 0;

‎drivers/remoteproc/remoteproc_internal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct rproc;
3535
* @get_boot_addr: get boot address to entry point specified in firmware
3636
*/
3737
struct rproc_fw_ops {
38-
struct resource_table *(*find_rsc_table) (struct rproc *rproc,
38+
struct resource_table *(*find_rsc_table)(struct rproc *rproc,
3939
const struct firmware *fw,
4040
int *tablesz);
4141
struct resource_table *(*find_loaded_rsc_table)(struct rproc *rproc,

‎drivers/remoteproc/ste_modem_rproc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ static int sproc_load_segments(struct rproc *rproc, const struct firmware *fw)
6767
static const struct ste_toc_entry *sproc_find_rsc_entry(const void *data)
6868
{
6969
int i;
70-
const struct ste_toc *toc;
71-
toc = data;
70+
const struct ste_toc *toc = data;
7271

7372
/* Search the table for the resource table */
7473
for (i = 0; i < SPROC_MAX_TOC_ENTRIES &&
@@ -230,6 +229,7 @@ static int sproc_start(struct rproc *rproc)
230229
static int sproc_stop(struct rproc *rproc)
231230
{
232231
struct sproc *sproc = rproc->priv;
232+
233233
sproc_dbg(sproc, "stop ste-modem\n");
234234

235235
return sproc->mdev->ops.power(sproc->mdev, false);

0 commit comments

Comments
 (0)