Skip to content

Commit 1d7f38d

Browse files
3V3RYONEmathieupoirier
authored andcommitted
remoteproc: k3: Refactor .get_loaded_rsc_table ops into common driver
The .get_loaded_rsc_table rproc ops implementations in TI K3 R5, DSP and M4 remoteproc drivers return a pointer to the resource table that was pre-loaded at the base address of the DDR region reserved for firmware usage. Refactor the implementations into ti_k3_common.c driver as k3_get_loaded_rsc_table() and register this common function as .get_loaded_rsc_table ops in R5, DSP and M4 drivers. Signed-off-by: Beleswar Padhi <[email protected]> Tested-by: Judith Mendez <[email protected]> Reviewed-by: Andrew Davis <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mathieu Poirier <[email protected]>
1 parent 8715d4c commit 1d7f38d

File tree

5 files changed

+38
-99
lines changed

5 files changed

+38
-99
lines changed

drivers/remoteproc/ti_k3_common.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,5 +318,38 @@ EXPORT_SYMBOL_GPL(k3_rproc_attach);
318318
int k3_rproc_detach(struct rproc *rproc) { return 0; }
319319
EXPORT_SYMBOL_GPL(k3_rproc_detach);
320320

321+
/*
322+
* This function implements the .get_loaded_rsc_table() callback and is used
323+
* to provide the resource table for a booted remote processor in IPC-only
324+
* mode. The remote processor firmwares follow a design-by-contract approach
325+
* and are expected to have the resource table at the base of the DDR region
326+
* reserved for firmware usage. This provides flexibility for the remote
327+
* processor to be booted by different bootloaders that may or may not have the
328+
* ability to publish the resource table address and size through a DT
329+
* property.
330+
*/
331+
struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc,
332+
size_t *rsc_table_sz)
333+
{
334+
struct k3_rproc *kproc = rproc->priv;
335+
struct device *dev = kproc->dev;
336+
337+
if (!kproc->rmem[0].cpu_addr) {
338+
dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found");
339+
return ERR_PTR(-ENOMEM);
340+
}
341+
342+
/*
343+
* NOTE: The resource table size is currently hard-coded to a maximum
344+
* of 256 bytes. The most common resource table usage for K3 firmwares
345+
* is to only have the vdev resource entry and an optional trace entry.
346+
* The exact size could be computed based on resource table address, but
347+
* the hard-coded value suffices to support the IPC-only mode.
348+
*/
349+
*rsc_table_sz = 256;
350+
return (__force struct resource_table *)kproc->rmem[0].cpu_addr;
351+
}
352+
EXPORT_SYMBOL_GPL(k3_get_loaded_rsc_table);
353+
321354
MODULE_LICENSE("GPL");
322355
MODULE_DESCRIPTION("TI K3 common Remoteproc code");

drivers/remoteproc/ti_k3_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,6 @@ int k3_rproc_start(struct rproc *rproc);
104104
int k3_rproc_stop(struct rproc *rproc);
105105
int k3_rproc_attach(struct rproc *rproc);
106106
int k3_rproc_detach(struct rproc *rproc);
107+
struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc,
108+
size_t *rsc_table_sz);
107109
#endif /* REMOTEPROC_TI_K3_COMMON_H */

drivers/remoteproc/ti_k3_dsp_remoteproc.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,6 @@ static int k3_dsp_rproc_start(struct rproc *rproc)
5858
return 0;
5959
}
6060

61-
/*
62-
* This function implements the .get_loaded_rsc_table() callback and is used
63-
* to provide the resource table for a booted DSP in IPC-only mode. The K3 DSP
64-
* firmwares follow a design-by-contract approach and are expected to have the
65-
* resource table at the base of the DDR region reserved for firmware usage.
66-
* This provides flexibility for the remote processor to be booted by different
67-
* bootloaders that may or may not have the ability to publish the resource table
68-
* address and size through a DT property. This callback is invoked only in
69-
* IPC-only mode.
70-
*/
71-
static struct resource_table *k3_dsp_get_loaded_rsc_table(struct rproc *rproc,
72-
size_t *rsc_table_sz)
73-
{
74-
struct k3_rproc *kproc = rproc->priv;
75-
struct device *dev = kproc->dev;
76-
77-
if (!kproc->rmem[0].cpu_addr) {
78-
dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found");
79-
return ERR_PTR(-ENOMEM);
80-
}
81-
82-
/*
83-
* NOTE: The resource table size is currently hard-coded to a maximum
84-
* of 256 bytes. The most common resource table usage for K3 firmwares
85-
* is to only have the vdev resource entry and an optional trace entry.
86-
* The exact size could be computed based on resource table address, but
87-
* the hard-coded value suffices to support the IPC-only mode.
88-
*/
89-
*rsc_table_sz = 256;
90-
return (__force struct resource_table *)kproc->rmem[0].cpu_addr;
91-
}
92-
9361
/*
9462
* Custom function to translate a DSP device address (internal RAMs only) to a
9563
* kernel virtual address. The DSPs can access their RAMs at either an internal
@@ -156,7 +124,7 @@ static const struct rproc_ops k3_dsp_rproc_ops = {
156124
.detach = k3_rproc_detach,
157125
.kick = k3_rproc_kick,
158126
.da_to_va = k3_dsp_rproc_da_to_va,
159-
.get_loaded_rsc_table = k3_dsp_get_loaded_rsc_table,
127+
.get_loaded_rsc_table = k3_get_loaded_rsc_table,
160128
};
161129

162130
static int k3_dsp_rproc_of_get_memories(struct platform_device *pdev,

drivers/remoteproc/ti_k3_m4_remoteproc.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,6 @@
2121
#include "ti_sci_proc.h"
2222
#include "ti_k3_common.h"
2323

24-
/*
25-
* This function implements the .get_loaded_rsc_table() callback and is used
26-
* to provide the resource table for a booted remote processor in IPC-only
27-
* mode. The remote processor firmwares follow a design-by-contract approach
28-
* and are expected to have the resource table at the base of the DDR region
29-
* reserved for firmware usage. This provides flexibility for the remote
30-
* processor to be booted by different bootloaders that may or may not have the
31-
* ability to publish the resource table address and size through a DT
32-
* property.
33-
*/
34-
static struct resource_table *k3_m4_get_loaded_rsc_table(struct rproc *rproc,
35-
size_t *rsc_table_sz)
36-
{
37-
struct k3_rproc *kproc = rproc->priv;
38-
struct device *dev = kproc->dev;
39-
40-
if (!kproc->rmem[0].cpu_addr) {
41-
dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found");
42-
return ERR_PTR(-ENOMEM);
43-
}
44-
45-
/*
46-
* NOTE: The resource table size is currently hard-coded to a maximum
47-
* of 256 bytes. The most common resource table usage for K3 firmwares
48-
* is to only have the vdev resource entry and an optional trace entry.
49-
* The exact size could be computed based on resource table address, but
50-
* the hard-coded value suffices to support the IPC-only mode.
51-
*/
52-
*rsc_table_sz = 256;
53-
return (__force struct resource_table *)kproc->rmem[0].cpu_addr;
54-
}
55-
5624
/*
5725
* Custom function to translate a remote processor device address (internal
5826
* RAMs only) to a kernel virtual address. The remote processors can access
@@ -253,7 +221,7 @@ static const struct rproc_ops k3_m4_rproc_ops = {
253221
.detach = k3_rproc_detach,
254222
.kick = k3_rproc_kick,
255223
.da_to_va = k3_m4_rproc_da_to_va,
256-
.get_loaded_rsc_table = k3_m4_get_loaded_rsc_table,
224+
.get_loaded_rsc_table = k3_get_loaded_rsc_table,
257225
};
258226

259227
static int k3_m4_rproc_probe(struct platform_device *pdev)

drivers/remoteproc/ti_k3_r5_remoteproc.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -559,38 +559,6 @@ static int k3_r5_rproc_stop(struct rproc *rproc)
559559
return ret;
560560
}
561561

562-
/*
563-
* This function implements the .get_loaded_rsc_table() callback and is used
564-
* to provide the resource table for the booted R5F in IPC-only mode. The K3 R5F
565-
* firmwares follow a design-by-contract approach and are expected to have the
566-
* resource table at the base of the DDR region reserved for firmware usage.
567-
* This provides flexibility for the remote processor to be booted by different
568-
* bootloaders that may or may not have the ability to publish the resource table
569-
* address and size through a DT property. This callback is invoked only in
570-
* IPC-only mode.
571-
*/
572-
static struct resource_table *k3_r5_get_loaded_rsc_table(struct rproc *rproc,
573-
size_t *rsc_table_sz)
574-
{
575-
struct k3_rproc *kproc = rproc->priv;
576-
struct device *dev = kproc->dev;
577-
578-
if (!kproc->rmem[0].cpu_addr) {
579-
dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found");
580-
return ERR_PTR(-ENOMEM);
581-
}
582-
583-
/*
584-
* NOTE: The resource table size is currently hard-coded to a maximum
585-
* of 256 bytes. The most common resource table usage for K3 firmwares
586-
* is to only have the vdev resource entry and an optional trace entry.
587-
* The exact size could be computed based on resource table address, but
588-
* the hard-coded value suffices to support the IPC-only mode.
589-
*/
590-
*rsc_table_sz = 256;
591-
return (__force struct resource_table *)kproc->rmem[0].cpu_addr;
592-
}
593-
594562
/*
595563
* Internal Memory translation helper
596564
*
@@ -1042,7 +1010,7 @@ static int k3_r5_rproc_configure_mode(struct k3_rproc *kproc)
10421010
kproc->rproc->ops->attach = k3_rproc_attach;
10431011
kproc->rproc->ops->detach = k3_rproc_detach;
10441012
kproc->rproc->ops->get_loaded_rsc_table =
1045-
k3_r5_get_loaded_rsc_table;
1013+
k3_get_loaded_rsc_table;
10461014
} else if (!c_state) {
10471015
dev_info(cdev, "configured R5F for remoteproc mode\n");
10481016
ret = 0;

0 commit comments

Comments
 (0)