ppc32: odd fixes and improvements in ppc_sys
PATCH 1/4 ppc32: odd fixes and improvements in ppc_sys
This consists of offsets fix in ..._devices.c, and update of ppc_sys_fixup_mem_resource() function to prevent subsequent fixups
---
arch/ppc/syslib/mpc8xx_devices.c | 25 +++++++++++++++++++------ arch/ppc/syslib/ppc_sys.c | 4 +++- arch/ppc/syslib/pq2_sys.c | 8 ++++---- include/asm-ppc/ppc_sys.h | 2 ++ 4 files changed, 28 insertions(+), 11 deletions(-)
arch/ppc/syslib/mpc8xx_devices.c +19 -6
@@ -170,12 +170,18 @@ struct platform_device ppc_sys_platform_ [MPC8xx_CPM_SMC1] = { .name = "fsl-cpm-smc", .id = 1, - .num_resources = 2, + .num_resources = 3, .resource = (struct resource[]) { { .name = "regs", - .start = 0xa82, - .end = 0xa91, + .start = 0xa80, + .end = 0xa8f, + .flags = IORESOURCE_MEM, + }, + { + .name = "pram", + .start = 0x3e80, + .end = 0x3ebf, .flags = IORESOURCE_MEM, }, {
@@ -189,15 +195,22 @@ struct platform_device ppc_sys_platform_ [MPC8xx_CPM_SMC2] = { .name = "fsl-cpm-smc", .id = 2, - .num_resources = 2, + .num_resources = 3, .resource = (struct resource[]) { { .name = "regs", - .start = 0xa92, - .end = 0xaa1, + .start = 0xa90, + .end = 0xa9f, .flags = IORESOURCE_MEM, }, { + .name = "pram", + .start = 0x3f80, + .end = 0x3fbf, + .flags = IORESOURCE_MEM, + + }, + { .name = "interrupt", .start = MPC8xx_INT_SMC2, .end = MPC8xx_INT_SMC2,
arch/ppc/syslib/ppc_sys.c +3 -1
@@ -109,9 +109,11 @@ ppc_sys_fixup_mem_resource(struct platfoint i;for (i =0 ; i < pdev->num_resources; i++) {struct resource *r = &pdev->resource[i]; -if ((r->flags &IORESOURCE_MEM ) ==IORESOURCE_MEM ) { +if (((r->flags &IORESOURCE_MEM ) ==IORESOURCE_MEM ) && + ((r->flags &PPC_SYS_IORESOURCE_FIXUPPED ) !=PPC_SYS_IORESOURCE_FIXUPPED )) { r->start += paddr; r->end += paddr; + r->flags |=PPC_SYS_IORESOURCE_FIXUPPED ; } } }
arch/ppc/syslib/pq2_sys.c +4 -4
@@ -113,13 +113,13 @@ struct ppc_sys_spec ppc_sys_specs[] = { .ppc_sys_name = "8248", .mask = 0x0000ff00, .value = 0x00000c00, - .num_devices = 11, + .num_devices = 12, .device_list = (enum ppc_sys_devices []) { MPC82xx_CPM_FCC1, MPC82xx_CPM_FCC2, MPC82xx_CPM_SCC1, - MPC82xx_CPM_SCC2, MPC82xx_CPM_SCC3, MPC82xx_CPM_SMC1, - MPC82xx_CPM_SMC2, MPC82xx_CPM_SPI, MPC82xx_CPM_I2C, - MPC82xx_CPM_USB, MPC82xx_SEC1, + MPC82xx_CPM_SCC2, MPC82xx_CPM_SCC3, MPC82xx_CPM_SCC4, + MPC82xx_CPM_SMC1, MPC82xx_CPM_SMC2, MPC82xx_CPM_SPI, + MPC82xx_CPM_I2C, MPC82xx_CPM_USB, MPC82xx_SEC1, }, }, {
include/asm-ppc/ppc_sys.h +2 -0
@@ -39,6 +39,8 @@#error "need definition of ppc_sys_devices"#endif +#define PPC_SYS_IORESOURCE_FIXUPPED 0x00000001 +struct ppc_sys_spec {/* PPC sys is matched via (ID & mask) == value, id could be * PVR, SVR, IMMR, * etc. */
PATCH 2/4 CPM_UART: Convert to use platform devices
This is intended to make the driver code more generic and flexible, to get rid of board-specific layouts within driver, and generic rehaul, yet keeping compatibility with the existing stuff utilizing it, being compatible with legacy behavior (but with complaints that legacy mode used).
---
drivers/serial/cpm_uart/cpm_uart.h | 16 +- drivers/serial/cpm_uart/cpm_uart_core.c | 259 +++++++++++++++++++++++++------ drivers/serial/cpm_uart/cpm_uart_cpm1.c | 47 ------ drivers/serial/cpm_uart/cpm_uart_cpm2.c | 9 - 4 files changed, 220 insertions(+), 111 deletions(-)
drivers/serial/cpm_uart/cpm_uart.h +9 -7
@@ -10,6 +10,8 @@#define CPM_UART_H #include <linux/config.h> +#include <linux/platform_device.h> +#include <linux/fs_uart_pd.h> #if defined(CONFIG_CPM2 )#include "cpm_uart_cpm2.h"
@@ -26,14 +28,14 @@#define FLAG_SMC 0x00000002#define FLAG_CONSOLE 0x00000001 -#define UART_SMC1 0 -#define UART_SMC2 1 -#define UART_SCC1 2 -#define UART_SCC2 3 -#define UART_SCC3 4 -#define UART_SCC4 5 +#define UART_SMC1 fsid_smc1_uart +#define UART_SMC2 fsid_smc2_uart +#define UART_SCC1 fsid_scc1_uart +#define UART_SCC2 fsid_scc2_uart +#define UART_SCC3 fsid_scc3_uart +#define UART_SCC4 fsid_scc4_uart -#define UART_NR 6 +#define UART_NR fs_uart_nr#define RX_NUM_FIFO 4#define RX_BUF_SIZE 32
drivers/serial/cpm_uart/cpm_uart_core.c +211 -48
337 lines not on this page · raw message
drivers/serial/cpm_uart/cpm_uart_cpm1.c +0 -47
58 lines not on this page · raw message
drivers/serial/cpm_uart/cpm_uart_cpm2.c +0 -9
@@ -142,14 +142,6 @@ void scc2_lineif(struct uart_cpm_port *p* be supported in a sane fashion. */ #ifndef CONFIG_STX_GP3 -#ifdef CONFIG_MPC8560_ADS -volatile iop_cpm2_t *io = &cpm2_immr->im_ioport; - io->iop_ppard |=0x00000018 ; - io->iop_psord &= ~0x00000008 ;/* Rx */ - io->iop_psord &= ~0x00000010 ;/* Tx */ - io->iop_pdird &= ~0x00000008 ;/* Rx */ - io->iop_pdird |=0x00000010 ;/* Tx */ -#else volatile iop_cpm2_t *io = &cpm2_immr->im_ioport; io->iop_pparb |=0x008b0000 ; io->iop_pdirb |=0x00880000 ;
@@ -157,7 +149,6 @@ void scc2_lineif(struct uart_cpm_port *p io->iop_pdirb &= ~0x00030000 ; io->iop_psorb &= ~0x00030000 ;#endif -#endif cpm2_immr->im_cpmux.cmx_scr &=0xff00ffff ; cpm2_immr->im_cpmux.cmx_scr |=0x00090000 ; pinfo->brg =2 ;
PATCH 3/4 PPC32: Update board-specific code of the CPM UART users
In reply to Vitaly BordugThis has the relevant updates/additions to the BSP code so that proper platform_info struct well be passed to the CPM UART drivers. The changes covered mpc866ads, mpc885ads and mpc8272ads.
---
arch/ppc/platforms/mpc8272ads_setup.c | 114 +++++++++++++++++++++++++++ arch/ppc/platforms/mpc866ads_setup.c | 140 +++++++++++++++++++++++++++++++++ arch/ppc/platforms/mpc885ads_setup.c | 131 +++++++++++++++++++++++++++++++ arch/ppc/platforms/pq2ads.c | 31 +++++++ 4 files changed, 415 insertions(+), 1 deletions(-)
arch/ppc/platforms/mpc8272ads_setup.c +114 -0
@@ -26,11 +26,35 @@#include <asm/irq.h> #include <asm/ppc_sys.h> #include <asm/ppcboot.h> +#include <linux/fs_uart_pd.h> #include "pq2ads_pd.h" static void init_fcc1_ioports (void );static void init_fcc2_ioports (void ); +static void init_scc1_uart_ioports (void ); +static void init_scc4_uart_ioports (void ); + +static struct fs_uart_platform_info mpc8272_uart_pdata[] = { + [fsid_scc1_uart] = { + .init_ioports = init_scc1_uart_ioports, + .fs_no = fsid_scc1_uart, + .brg =1 , + .tx_num_fifo =4 , + .tx_buf_size =32 , + .rx_num_fifo =4 , + .rx_buf_size =32 , + }, + [fsid_scc4_uart] = { + .init_ioports = init_scc4_uart_ioports, + .fs_no = fsid_scc4_uart, + .brg =4 , + .tx_num_fifo =4 , + .tx_buf_size =32 , + .rx_num_fifo =4 , + .rx_buf_size =32 , + }, +};static struct fs_mii_bus_info mii_bus_info = { .method = fsmii_bitbang,
@@ -201,6 +225,55 @@ static void __init mpc8272ads_fixup_enet } } +static void mpc8272ads_fixup_uart_pdata (struct platform_device *pdev, +int idx) +{ +bd_t *bd = (bd_t *) __res; +struct fs_uart_platform_info *pinfo; +int num =ARRAY_SIZE (mpc8272_uart_pdata); +int id =fs_uart_id_scc2fsid (idx); + +/* no need to alter anything if console */ +if ((id <= num) && (!pdev->dev.platform_data)) { + pinfo = &mpc8272_uart_pdata[id]; + pinfo->uart_clk = bd->bi_intfreq; + pdev->dev.platform_data = pinfo; + } +} + +static void init_scc1_uart_ioports (void ) +{ +cpm2_map_t * immap =ioremap (CPM_MAP_ADDR ,sizeof (cpm2_map_t)); + +/* SCC1 is only on port D */ +setbits32 (&immap->im_ioport.iop_ppard,0x00000003 ); +clrbits32 (&immap->im_ioport.iop_psord,0x00000001 ); +setbits32 (&immap->im_ioport.iop_psord,0x00000002 ); +clrbits32 (&immap->im_ioport.iop_pdird,0x00000001 ); +setbits32 (&immap->im_ioport.iop_pdird,0x00000002 ); + +/* Wire BRG1 to SCC1 */ +clrbits32 (&immap->im_cpmux.cmx_scr,0x00ffffff ); + +iounmap (immap); +} + +static void init_scc4_uart_ioports (void ) +{ +cpm2_map_t * immap =ioremap (CPM_MAP_ADDR ,sizeof (cpm2_map_t)); + +setbits32 (&immap->im_ioport.iop_ppard,0x00000600 ); +clrbits32 (&immap->im_ioport.iop_psord,0x00000600 ); +clrbits32 (&immap->im_ioport.iop_pdird,0x00000200 ); +setbits32 (&immap->im_ioport.iop_pdird,0x00000400 ); + +/* Wire BRG4 to SCC4 */ +clrbits32 (&immap->im_cpmux.cmx_scr,0x000000ff ); +setbits32 (&immap->im_cpmux.cmx_scr,0x0000001b ); + +iounmap (immap); +} +static int mpc8272ads_platform_notify (struct device *dev) {static const struct platform_notify_dev_map dev_map[] = {
@@ -209,6 +282,10 @@ static int mpc8272ads_platform_notify(st .rtn = mpc8272ads_fixup_enet_pdata }, { + .bus_id = "fsl-cpm-scc:uart", + .rtn = mpc + }, + { .bus_id = NULL } };
@@ -230,7 +307,44 @@ int __init mpc8272ads_init(void)ppc_sys_device_enable (MPC82xx_CPM_FCC1);ppc_sys_device_enable (MPC82xx_CPM_FCC2); +/* to be ready for console, let's attach pdata here */ +#ifdef CONFIG_SERIAL_CPM_SCC1 +ppc_sys_device_setfunc (MPC82xx_CPM_SCC1,PPC_SYS_FUNC_UART ); +ppc_sys_device_enable (MPC82xx_CPM_SCC1); + +#endif + +#ifdef CONFIG_SERIAL_CPM_SCC4 +ppc_sys_device_setfunc (MPC82xx_CPM_SCC4,PPC_SYS_FUNC_UART ); +ppc_sys_device_enable (MPC82xx_CPM_SCC4); +#endif + +return 0 ; } +/* +To prevent confusion, console selection is gross: +by 0 assumed SCC1 and by 1 assumed SCC4 +*/ +struct platform_device *early_uart_get_pdev (int index) +{ +bd_t *bd = (bd_t *) __res; +struct fs_uart_platform_info *pinfo; + +struct platform_device * pdev =NULL ; +if (index) {/*assume SCC4 here*/ + pdev = &ppc_sys_platform_devices[MPC82xx_CPM_SCC4]; + pinfo = &mpc8272<F12 >_uart_pdata[1 ]; + }else {/*over SCC1*/ + pdev = &ppc_sys_platform_devices[MPC82xx_CPM_SCC1]; + pinfo = &mpc8272_uart_pdata[0 ]; + } + + pinfo->uart_clk = bd->bi_intfreq; + pdev->dev.platform_data = pinfo; +ppc_sys_fixup_mem_resource (pdev,IMAP_ADDR ); +return NULL ; +} +arch_initcall (mpc8272ads_init);
arch/ppc/platforms/mpc866ads_setup.c +140 -0
192 lines not on this page · raw message
arch/ppc/platforms/mpc885ads_setup.c +131 -0
183 lines not on this page · raw message
arch/ppc/platforms/pq2ads.c +30 -1
@@ -14,11 +14,40 @@#include <linux/init.h> +#include <asm/io.h> #include <asm/mpc8260.h> +#include <asm/cpm2.h> +#include <asm/immap_cpm2.h> void __init m82xx_board_setup (void ) { +cpm2_map_t * immap =ioremap (CPM_MAP_ADDR ,sizeof (cpm2_map_t)); +u32 *bcsr =ioremap (BCSR_ADDR +4 ,sizeof (u32)); +/* Enable the 2nd UART port */ - *(volatile uint *)(BCSR_ADDR +4 ) &= ~BCSR1_RS232_EN2 ; +clrbits32 (bcsr,BCSR1_RS232_EN2 ); + +#ifdef CONFIG_SERIAL_CPM_SCC1 +clrbits32 ((u32 *)&immap->im_scc[0 ].scc_sccm,UART_SCCM_TX |UART_SCCM_RX ); +clrbits32 ((u32 *)&immap->im_scc[0 ].scc_gsmrl,SCC_GSMRL_ENR |SCC_GSMRL_ENT ); +#endif + +#ifdef CONFIG_SERIAL_CPM_SCC2 +clrbits32 ((u32 *)&immap->im_scc[1 ].scc_sccm,UART_SCCM_TX |UART_SCCM_RX ); +clrbits32 ((u32 *)&immap->im_scc[1 ].scc_gsmrl,SCC_GSMRL_ENR |SCC_GSMRL_ENT ); +#endif + +#ifdef CONFIG_SERIAL_CPM_SCC3 +clrbits32 ((u32 *)&immap->im_scc[2 ].scc_sccm,UART_SCCM_TX |UART_SCCM_RX ); +clrbits32 ((u32 *)&immap->im_scc[2 ].scc_gsmrl,SCC_GSMRL_ENR |SCC_GSMRL_ENT ); +#endif + +#ifdef CONFIG_SERIAL_CPM_SCC4 +clrbits32 ((u32 *)&immap->im_scc[3 ].scc_sccm,UART_SCCM_TX |UART_SCCM_RX ); +clrbits32 ((u32 *)&immap->im_scc[3 ].scc_gsmrl,SCC_GSMRL_ENR |SCC_GSMRL_ENT ); +#endif + +iounmap (bcsr); +iounmap (immap); }
PATCH 4/4 ppc32 CPM_UART: Fixed odd address translations
In reply to Vitaly BordugCurrent address translation methods can produce wrong results, because virt_to_bus and vice versa may not produce correct offsets on dma-allocated memory. The right way is, while tracking both phys and virt address of the window that has been allocated for boffer descriptors, and use those numbers to compute the offset and make translation properly.
---
drivers/serial/cpm_uart/cpm_uart.h | 33 +++++++++++++++++++++++++++++++ drivers/serial/cpm_uart/cpm_uart_core.c | 31 ++++++++--------------------- drivers/serial/cpm_uart/cpm_uart_cpm1.c | 7 ++++--- drivers/serial/cpm_uart/cpm_uart_cpm2.c | 5 ++++- 4 files changed, 50 insertions(+), 26 deletions(-)
drivers/serial/cpm_uart/cpm_uart.h +33 -0
@@ -66,6 +66,7 @@ struct uart_cpm_port {uint dp_addr;void *mem_addr;dma_addr_t dma_addr; +u32 mem_size;/* helpers */ int baud;int bits;
@@ -92,4 +93,36 @@ void scc2_lineif(struct uart_cpm_port *pvoid scc3_lineif (struct uart_cpm_port *pinfo);void scc4_lineif (struct uart_cpm_port *pinfo); +/* +virtual to phys transtalion +*/ +static inline unsigned long cpu2cpm_addr (void * addr,struct uart_cpm_port *pinfo) +{ +int offset; +u32 val = (u32 )addr; +/* sane check */ +if ((val >= (u32 )pinfo->mem_addr) && + (val<((u32 )pinfo->mem_addr + pinfo->mem_size))) { + offset = val - (u32 )pinfo->mem_addr; +return pinfo->dma_addr+offset; + } +printk ("%s(): address %x to translate out of range!\n" , __FUNCTION__, val); +return 0 ; +} + +static inline void *cpm2cpu_addr (unsigned long addr,struct uart_cpm_port *pinfo) +{ +int offset; +u32 val = addr; +/* sane check */ +if ((val >= pinfo->dma_addr) && + (val<(pinfo->dma_addr + pinfo->mem_size))) { + offset = val - (u32 )pinfo->dma_addr; +return (void *)(pinfo->mem_addr+offset); + } +printk ("%s(): address %x to translate out of range!\n" , __FUNCTION__, val); +return 0 ; +} + +#endif /* CPM_UART_H */
drivers/serial/cpm_uart/cpm_uart_core.c +9 -22
@@ -72,19 +72,6 @@ static void cpm_uart_initbd(struct uart_/**************************************************************/ -static inline unsigned long cpu2cpm_addr (void *addr) -{ -if ((unsigned long )addr >=CPM_ADDR ) -return (unsigned long )addr; -return virt_to_bus (addr); -} - -static inline void *cpm2cpu_addr (unsigned long addr) -{ -if (addr >=CPM_ADDR ) -return (void *)addr; -return bus_to_virt (addr); -}/* Place-holder for board-specific stuff */ struct platform_device* __attribute__ ((weak)) __init
@@ -290,7 +277,7 @@ static void cpm_uart_int_rx(struct uart_ }/* get pointer */ - cp =cpm2cpu_addr (bdp->cbd_bufaddr); + cp =cpm2cpu_addr (bdp->cbd_bufaddr, pinfo);/* loop through the buffer */ while (i-- >0 ) {
@@ -633,7 +620,7 @@ static int cpm_uart_tx_pump(struct uart_/* Pick next descriptor and fill from buffer */ bdp = pinfo->tx_cur; - p =cpm2cpu_addr (bdp->cbd_bufaddr); + p =cpm2cpu_addr (bdp->cbd_bufaddr, pinfo); *p++ = port->x_char; bdp->cbd_datlen =1 ;
@@ -660,7 +647,7 @@ static int cpm_uart_tx_pump(struct uart_while (!(bdp->cbd_sc &BD_SC_READY ) && (xmit->tail != xmit->head)) { count =0 ; - p =cpm2cpu_addr (bdp->cbd_bufaddr); + p =cpm2cpu_addr (bdp->cbd_bufaddr, pinfo);while (count < pinfo->tx_fifosize) { *p++ = xmit->buf[xmit->tail]; xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 );
@@ -709,12 +696,12 @@ static void cpm_uart_initbd(struct uart_ mem_addr = pinfo->mem_addr; bdp = pinfo->rx_cur = pinfo->rx_bd_base;for (i =0 ; i < (pinfo->rx_nrfifos -1 ); i++, bdp++) { - bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr); + bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr, pinfo); bdp->cbd_sc =BD_SC_EMPTY |BD_SC_INTRPT ; mem_addr += pinfo->rx_fifosize; } - bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr); + bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr, pinfo); bdp->cbd_sc =BD_SC_WRAP |BD_SC_EMPTY |BD_SC_INTRPT ;/* Set the physical address of the host memory
@@ -724,12 +711,12 @@ static void cpm_uart_initbd(struct uart_ mem_addr = pinfo->mem_addr +L1_CACHE_ALIGN (pinfo->rx_nrfifos * pinfo->rx_fifosize); bdp = pinfo->tx_cur = pinfo->tx_bd_base;for (i =0 ; i < (pinfo->tx_nrfifos -1 ); i++, bdp++) { - bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr); + bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr, pinfo); bdp->cbd_sc =BD_SC_INTRPT ; mem_addr += pinfo->tx_fifosize; } - bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr); + bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr, pinfo); bdp->cbd_sc =BD_SC_WRAP |BD_SC_INTRPT ; }
@@ -1099,7 +1086,7 @@ static void cpm_uart_console_write(struc* If the buffer address is in the CPM DPRAM, don't * convert it. */ - cp =cpm2cpu_addr (bdp->cbd_bufaddr); + cp =cpm2cpu_addr (bdp->cbd_bufaddr, pinfo); *cp = *s;
@@ -1116,7 +1103,7 @@ static void cpm_uart_console_write(strucwhile ((bdp->cbd_sc &BD_SC_READY ) !=0 ) ; - cp =cpm2cpu_addr (bdp->cbd_bufaddr); + cp =cpm2cpu_addr (bdp->cbd_bufaddr, pinfo); *cp =13 ; bdp->cbd_datlen =1 ;
drivers/serial/cpm_uart/cpm_uart_cpm1.c +4 -3
@@ -144,7 +144,7 @@ int cpm_uart_allocbuf(struct uart_cpm_po/* was hostalloc but changed cause it blows away the */ /* large tlb mapping when pinning the kernel area */ mem_addr = (u8 *)cpm_dpram_addr (cpm_dpalloc (memsz,8 )); - dma_addr =0 ; + dma_addr = (u32 )mem_addr; }else mem_addr =dma_alloc_coherent (NULL , memsz, &dma_addr,GFP_KERNEL );
@@ -157,8 +157,9 @@ int cpm_uart_allocbuf(struct uart_cpm_po } pinfo->dp_addr = dp_offset; - pinfo->mem_addr = mem_addr; - pinfo->dma_addr = dma_addr; + pinfo->mem_addr = mem_addr;/* virtual address*/ + pinfo->dma_addr = dma_addr;/* physical address*/ + pinfo->mem_size = memsz; pinfo->rx_buf = mem_addr; pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
drivers/serial/cpm_uart/cpm_uart_cpm2.c +4 -1
@@ -209,8 +209,10 @@ int cpm_uart_allocbuf(struct uart_cpm_po memsz =L1_CACHE_ALIGN (pinfo->rx_nrfifos * pinfo->rx_fifosize) +L1_CACHE_ALIGN (pinfo->tx_nrfifos * pinfo->tx_fifosize); -if (is_con) +if (is_con) { mem_addr =alloc_bootmem (memsz); + dma_addr = mem_addr; + }else mem_addr =dma_alloc_coherent (NULL , memsz, &dma_addr,GFP_KERNEL );
@@ -225,6 +227,7 @@ int cpm_uart_allocbuf(struct uart_cpm_po pinfo->dp_addr = dp_offset; pinfo->mem_addr = mem_addr; pinfo->dma_addr = dma_addr; + pinfo->mem_size = memsz; pinfo->rx_buf = mem_addr; pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
Re: [PATCH 4/4] ppc32 CPM_UART: Fixed odd address translations
Ouch.
I would convert the warning printk() to a BUG(), since such an address error
indicates deep trouble anyway...
And add a "likely()" indication around the range check.
Looks great otherwise!
Quoted 212 lines · Vitaly Bordug
Current address translation methods can produce wrong results, because
virt_to_busand vice versa may not produce correct offsets on dma-allocated memory. The right way is, while tracking both phys and virt address of the window that has been allocated for boffer descriptors, and use those numbers to compute the offset and make translation properly.Signed-off-by Vitaly Bordug <[email protected]>---
drivers/serial/cpm_uart/cpm_uart.h | 33 +++++++++++++++++++++++++++++++ drivers/serial/cpm_uart/cpm_uart_core.c | 31 ++++++++--------------------- drivers/serial/cpm_uart/cpm_uart_cpm1.c | 7 ++++--- drivers/serial/cpm_uart/cpm_uart_cpm2.c | 5 ++++- 4 files changed, 50 insertions(+), 26 deletions(-)drivers/serial/cpm_uart/cpm_uart.h +33
-0@@ -66,6 +66,7 @@ struct uart_cpm_port {uint dp_addr;void *mem_addr;dma_addr_t dma_addr; +u32 mem_size;/* helpers */ int baud;int bits;@@ -92,4 +93,36 @@ void scc2_lineif(struct uart_cpm_port *pvoid scc3_lineif (struct uart_cpm_port *pinfo);void scc4_lineif (struct uart_cpm_port *pinfo); +/* +virtual to phys transtalion +*/ +static inline unsigned long cpu2cpm_addr (void * addr,struct uart_cpm_port *pinfo) +{ +int offset; +u32 val = (u32 )addr; +/* sane check */ +if ((val >= (u32 )pinfo->mem_addr) && + (val<((u32 )pinfo->mem_addr + pinfo->mem_size))) { + offset = val - (u32 )pinfo->mem_addr; +return pinfo->dma_addr+offset; + } +printk ("%s(): address %x to translate out of range!\n" , __FUNCTION__, val); +return 0 ; +} + +static inline void *cpm2cpu_addr (unsigned long addr,struct uart_cpm_port *pinfo) +{ +int offset; +u32 val = addr; +/* sane check */ +if ((val >= pinfo->dma_addr) && + (val<(pinfo->dma_addr + pinfo->mem_size))) { + offset = val - (u32 )pinfo->dma_addr; +return (void *)(pinfo->mem_addr+offset); + } +printk ("%s(): address %x to translate out of range!\n" , __FUNCTION__, val); +return 0 ; +} + +#endif /* CPM_UART_H */ drivers/serial/cpm_uart/cpm_uart_core.c +9
-22@@ -72,19 +72,6 @@ static void cpm_uart_initbd(struct uart_/**************************************************************/ -static inline unsigned long cpu2cpm_addr (void *addr) -{ -if ((unsigned long )addr >=CPM_ADDR ) -return (unsigned long )addr; -return virt_to_bus (addr); -} - -static inline void *cpm2cpu_addr (unsigned long addr) -{ -if (addr >=CPM_ADDR ) -return (void *)addr; -return bus_to_virt (addr); -}/* Place-holder for board-specific stuff */ struct platform_device* __attribute__ ((weak)) __init@@ -290,7 +277,7 @@ static void cpm_uart_int_rx(struct uart_ }/* get pointer */ - cp =cpm2cpu_addr (bdp->cbd_bufaddr); + cp =cpm2cpu_addr (bdp->cbd_bufaddr, pinfo);/* loop through the buffer */ while (i-- >0 ) {@@ -633,7 +620,7 @@ static int cpm_uart_tx_pump(struct uart_/* Pick next descriptor and fill from buffer */ bdp = pinfo->tx_cur; - p =cpm2cpu_addr (bdp->cbd_bufaddr); + p =cpm2cpu_addr (bdp->cbd_bufaddr, pinfo); *p++ = port->x_char; bdp->cbd_datlen =1 ;@@ -660,7 +647,7 @@ static int cpm_uart_tx_pump(struct uart_while (!(bdp->cbd_sc &BD_SC_READY ) && (xmit->tail != xmit->head)) { count =0 ; - p =cpm2cpu_addr (bdp->cbd_bufaddr); + p =cpm2cpu_addr (bdp->cbd_bufaddr, pinfo);while (count < pinfo->tx_fifosize) { *p++ = xmit->buf[xmit->tail]; xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 );@@ -709,12 +696,12 @@ static void cpm_uart_initbd(struct uart_ mem_addr = pinfo->mem_addr; bdp = pinfo->rx_cur = pinfo->rx_bd_base;for (i =0 ; i < (pinfo->rx_nrfifos -1 ); i++, bdp++) { - bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr); + bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr, pinfo); bdp->cbd_sc =BD_SC_EMPTY |BD_SC_INTRPT ; mem_addr += pinfo->rx_fifosize; } - bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr); + bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr, pinfo); bdp->cbd_sc =BD_SC_WRAP |BD_SC_EMPTY |BD_SC_INTRPT ;/* Set the physical address of the host memory @@ -724,12 +711,12 @@ static void cpm_uart_initbd(struct uart_ mem_addr = pinfo->mem_addr +L1_CACHE_ALIGN (pinfo->rx_nrfifos * pinfo->rx_fifosize); bdp = pinfo->tx_cur = pinfo->tx_bd_base;for (i =0 ; i < (pinfo->tx_nrfifos -1 ); i++, bdp++) { - bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr); + bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr, pinfo); bdp->cbd_sc =BD_SC_INTRPT ; mem_addr += pinfo->tx_fifosize; } - bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr); + bdp->cbd_bufaddr =cpu2cpm_addr (mem_addr, pinfo); bdp->cbd_sc =BD_SC_WRAP |BD_SC_INTRPT ; }@@ -1099,7 +1086,7 @@ static void cpm_uart_console_write(struc* If the buffer address is in the CPM DPRAM, don't * convert it. */ - cp =cpm2cpu_addr (bdp->cbd_bufaddr); + cp =cpm2cpu_addr (bdp->cbd_bufaddr, pinfo); *cp = *s;@@ -1116,7 +1103,7 @@ static void cpm_uart_console_write(strucwhile ((bdp->cbd_sc &BD_SC_READY ) !=0 ) ; - cp =cpm2cpu_addr (bdp->cbd_bufaddr); + cp =cpm2cpu_addr (bdp->cbd_bufaddr, pinfo); *cp =13 ; bdp->cbd_datlen =1 ;drivers/serial/cpm_uart/cpm_uart_cpm1.c +4
-3@@ -144,7 +144,7 @@ int cpm_uart_allocbuf(struct uart_cpm_po/* was hostalloc but changed cause it blows away the */ /* large tlb mapping when pinning the kernel area */ mem_addr = (u8 *)cpm_dpram_addr (cpm_dpalloc (memsz,8 )); - dma_addr =0 ; + dma_addr = (u32 )mem_addr; }else mem_addr =dma_alloc_coherent (NULL , memsz, &dma_addr,GFP_KERNEL );@@ -157,8 +157,9 @@ int cpm_uart_allocbuf(struct uart_cpm_po } pinfo->dp_addr = dp_offset; - pinfo->mem_addr = mem_addr; - pinfo->dma_addr = dma_addr; + pinfo->mem_addr = mem_addr;/* virtual address*/ + pinfo->dma_addr = dma_addr;/* physical address*/ + pinfo->mem_size = memsz; pinfo->rx_buf = mem_addr; pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifosdrivers/serial/cpm_uart/cpm_uart_cpm2.c +4
-1@@ -209,8 +209,10 @@ int cpm_uart_allocbuf(struct uart_cpm_po memsz =L1_CACHE_ALIGN (pinfo->rx_nrfifos * pinfo->rx_fifosize) +L1_CACHE_ALIGN (pinfo->tx_nrfifos * pinfo->tx_fifosize); -if (is_con) +if (is_con) { mem_addr =alloc_bootmem (memsz); + dma_addr = mem_addr; + }else mem_addr =dma_alloc_coherent (NULL , memsz, &dma_addr,GFP_KERNEL );@@ -225,6 +227,7 @@ int cpm_uart_allocbuf(struct uart_cpm_po pinfo->dp_addr = dp_offset; pinfo->mem_addr = mem_addr; pinfo->dma_addr = dma_addr; + pinfo->mem_size = memsz; pinfo->rx_buf = mem_addr; pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos