Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

remoteproc: pru: Add pru_rproc_set_ctable() function

Some firmwares expect the OS drivers to configure the CTABLE
entries publishing dynamically allocated memory regions. For
example, the PRU Ethernet firmwares use the C28 and C30 entries
for retrieving the Shared RAM and System SRAM (OCMC) areas
allocated by the PRU Ethernet client driver.

Provide a way for users to do that through a new API,
pru_rproc_set_ctable(). The API returns 0 on success and
a negative value on error.

NOTE:
The programmable CTABLE entries are typically re-programmed by
the PRU firmwares when dealing with a certain block of memory
during block processing. This API provides an interface to the
PRU client drivers to publish a dynamically allocated memory
block with the PRU firmware using a CTABLE entry instead of a
negotiated address in shared memory. Additional synchronization
may be needed between the PRU client drivers and firmwares if
different addresses needs to be published at run-time reusing
the same CTABLE entry.

CTABLE for stands for "constant table".
Each CTable entry just holds the upper address bits so PRU can
reference to external memory with larger address bits.

For use case please see
prueth_sw_emac_config() in "drivers/net/ethernet/ti/prueth_switch.c"

/* Set in constant table C28 of PRUn to ICSS Shared memory */
pru_rproc_set_ctable(prueth->pru0, PRU_C28, sharedramaddr);
pru_rproc_set_ctable(prueth->pru1, PRU_C28, sharedramaddr);

/* Set in constant table C30 of PRUn to OCMC memory */
pru_rproc_set_ctable(prueth->pru0, PRU_C30, ocmcaddr);
pru_rproc_set_ctable(prueth->pru1, PRU_C30, ocmcaddr);

Signed-off-by: Andrew F. Davis <afd@ti.com>
Signed-off-by: Suman Anna <s-anna@ti.com>
Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Grzegorz Jaszczyk <grzegorz.jaszczyk@linaro.org>
Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
Link: https://lore.kernel.org/r/20230106121046.886863-6-danishanwar@ti.com
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>

authored by

Roger Quadros and committed by
Mathieu Poirier
10285340 2da812ff

+81
+59
drivers/remoteproc/pru_rproc.c
··· 120 120 * @mapped_irq: virtual interrupt numbers of created fw specific mapping 121 121 * @pru_interrupt_map: pointer to interrupt mapping description (firmware) 122 122 * @pru_interrupt_map_sz: pru_interrupt_map size 123 + * @rmw_lock: lock for read, modify, write operations on registers 123 124 * @dbg_single_step: debug state variable to set PRU into single step mode 124 125 * @dbg_continuous: debug state variable to restore PRU execution mode 125 126 * @evt_count: number of mapped events ··· 138 137 unsigned int *mapped_irq; 139 138 struct pru_irq_rsc *pru_interrupt_map; 140 139 size_t pru_interrupt_map_sz; 140 + spinlock_t rmw_lock; 141 141 u32 dbg_single_step; 142 142 u32 dbg_continuous; 143 143 u8 evt_count; ··· 153 151 void pru_control_write_reg(struct pru_rproc *pru, unsigned int reg, u32 val) 154 152 { 155 153 writel_relaxed(val, pru->mem_regions[PRU_IOMEM_CTRL].va + reg); 154 + } 155 + 156 + static inline 157 + void pru_control_set_reg(struct pru_rproc *pru, unsigned int reg, 158 + u32 mask, u32 set) 159 + { 160 + u32 val; 161 + unsigned long flags; 162 + 163 + spin_lock_irqsave(&pru->rmw_lock, flags); 164 + 165 + val = pru_control_read_reg(pru, reg); 166 + val &= ~mask; 167 + val |= (set & mask); 168 + pru_control_write_reg(pru, reg, val); 169 + 170 + spin_unlock_irqrestore(&pru->rmw_lock, flags); 156 171 } 157 172 158 173 static struct rproc *__pru_rproc_get(struct device_node *np, int index) ··· 287 268 rproc_put(rproc); 288 269 } 289 270 EXPORT_SYMBOL_GPL(pru_rproc_put); 271 + 272 + /** 273 + * pru_rproc_set_ctable() - set the constant table index for the PRU 274 + * @rproc: the rproc instance of the PRU 275 + * @c: constant table index to set 276 + * @addr: physical address to set it to 277 + * 278 + * Return: 0 on success, or errno in error case. 279 + */ 280 + int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr) 281 + { 282 + struct pru_rproc *pru = rproc->priv; 283 + unsigned int reg; 284 + u32 mask, set; 285 + u16 idx; 286 + u16 idx_mask; 287 + 288 + if (IS_ERR_OR_NULL(rproc)) 289 + return -EINVAL; 290 + 291 + if (!rproc->dev.parent || !is_pru_rproc(rproc->dev.parent)) 292 + return -ENODEV; 293 + 294 + /* pointer is 16 bit and index is 8-bit so mask out the rest */ 295 + idx_mask = (c >= PRU_C28) ? 0xFFFF : 0xFF; 296 + 297 + /* ctable uses bit 8 and upwards only */ 298 + idx = (addr >> 8) & idx_mask; 299 + 300 + /* configurable ctable (i.e. C24) starts at PRU_CTRL_CTBIR0 */ 301 + reg = PRU_CTRL_CTBIR0 + 4 * (c >> 1); 302 + mask = idx_mask << (16 * (c & 1)); 303 + set = idx << (16 * (c & 1)); 304 + 305 + pru_control_set_reg(pru, reg, mask, set); 306 + 307 + return 0; 308 + } 309 + EXPORT_SYMBOL_GPL(pru_rproc_set_ctable); 290 310 291 311 static inline u32 pru_debug_read_reg(struct pru_rproc *pru, unsigned int reg) 292 312 { ··· 998 940 pru->rproc = rproc; 999 941 pru->fw_name = fw_name; 1000 942 pru->client_np = NULL; 943 + spin_lock_init(&pru->rmw_lock); 1001 944 mutex_init(&pru->lock); 1002 945 1003 946 for (i = 0; i < ARRAY_SIZE(mem_names); i++) {
+22
include/linux/remoteproc/pruss.h
··· 28 28 PRUSS_NUM_PRUS, 29 29 }; 30 30 31 + /* 32 + * enum pru_ctable_idx - Configurable Constant table index identifiers 33 + */ 34 + enum pru_ctable_idx { 35 + PRU_C24 = 0, 36 + PRU_C25, 37 + PRU_C26, 38 + PRU_C27, 39 + PRU_C28, 40 + PRU_C29, 41 + PRU_C30, 42 + PRU_C31, 43 + }; 44 + 31 45 struct device_node; 46 + struct rproc; 32 47 33 48 #if IS_ENABLED(CONFIG_PRU_REMOTEPROC) 34 49 35 50 struct rproc *pru_rproc_get(struct device_node *np, int index, 36 51 enum pruss_pru_id *pru_id); 37 52 void pru_rproc_put(struct rproc *rproc); 53 + int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr); 38 54 39 55 #else 40 56 ··· 61 45 } 62 46 63 47 static inline void pru_rproc_put(struct rproc *rproc) { } 48 + 49 + static inline int pru_rproc_set_ctable(struct rproc *rproc, 50 + enum pru_ctable_idx c, u32 addr) 51 + { 52 + return -EOPNOTSUPP; 53 + } 64 54 65 55 #endif /* CONFIG_PRU_REMOTEPROC */ 66 56