PCI: rcar: Do not abort on too many inbound dma-ranges
Subsystems (4)
PATCH 1/2 PCI: rcar: Do not abort on too many inbound dma-ranges
From: Marek Vasut <[email protected]>
In case the "dma-ranges" DT property contains either too many ranges or the range start address is unaligned in such a way that populating the range into the controller requires multiple entries, a situation may occur where all ranges cannot be loaded into the controller.
Currently, the driver refuses to probe in such a situation. Relax this behavior, load as many ranges as possible and warn if some ranges do not fit anymore.
--- drivers/pci/controller/pcie-rcar.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/controller/pcie-rcar.c +3 -2
@@ -1069,8 +1069,9 @@ static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie, idx +=2 ;if (idx >MAX_NR_INBOUND_MAPS ) { -dev_err (pcie->dev,"Failed to map inbound regions!\n" ); -return -EINVAL ; +dev_warn (pcie->dev, +"Too many inbound regions, not all are mapped.\n" ); +break ; } } *index = idx;
Signature · 1 line
2.20.1
PATCH 2/2 PCI: rcar: Recalculate inbound range alignment for each controller entry
From: Marek Vasut <[email protected]>
Due to hardware constraints, the size of each inbound range entry populated into the controller cannot be larger than the alignment of the entry's start address. Currently, the alignment for each "dma-ranges" inbound range is calculated only once for each range and the increment for programming the controller is also derived from it only once. Thus, a "dma-ranges" entry describing a memory at 0x48000000 and size 0x38000000 would lead to multiple controller entries, each 0x08000000 long.
This is inefficient, especially considering that by adding the size to the start address, the alignment increases. This patch moves the alignment calculation into the loop populating the controller entries, thus updating the alignment for each controller entry.
--- drivers/pci/controller/pcie-rcar.c | 33 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-)
drivers/pci/controller/pcie-rcar.c +17 -16
@@ -1029,25 +1029,26 @@ static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,if (restype &IORESOURCE_PREFETCH ) flags |=LAM_PREFETCH ; -/* -* If the size of the range is larger than the alignment of the start -* address, we have to use multiple entries to perform the mapping. -*/ -if (cpu_addr >0 ) { -unsigned long nr_zeros =__ffs64 (cpu_addr); -u64 alignment =1ULL << nr_zeros; +while (cpu_addr < cpu_end) { +/* +* If the size of the range is larger than the alignment of +* the start address, we have to use multiple entries to +* perform the mapping. +*/ +if (cpu_addr >0 ) { +unsigned long nr_zeros =__ffs64 (cpu_addr); +u64 alignment =1ULL << nr_zeros; - size =min (range->size, alignment); - }else { - size = range->size; - } -/* Hardware supports max 4GiB inbound region */ - size =min (size,1ULL <<32 ); + size =min (range->size, alignment); + }else { + size = range->size; + } +/* Hardware supports max 4GiB inbound region */ + size =min (size,1ULL <<32 ); - mask =roundup_pow_of_two (size) -1 ; - mask &= ~0xf ; + mask =roundup_pow_of_two (size) -1 ; + mask &= ~0xf ; -while (cpu_addr < cpu_end) {/* * Set up 64-bit inbound regions as the range parser doesn't * distinguish between 32 and 64-bit types.
Signature · 1 line
2.20.1
Re: [PATCH 2/2] PCI: rcar: Recalculate inbound range alignment for each controller entry
Quoted 16 lines · On Tue, Jul 09, 2019 at 03:15:59AM +0200, [email protected] wrote:
From: Marek Vasut <[email protected]>
Due to hardware constraints, the size of each inbound range entry populated into the controller cannot be larger than the alignment of the entry's start address. Currently, the alignment for each "dma-ranges" inbound range is calculated only once for each range and the increment for programming the controller is also derived from it only once. Thus, a "dma-ranges" entry describing a memory at
0x48000000and size0x38000000would lead to multiple controller entries, each0x08000000long.This is inefficient, especially considering that by adding the size to the start address, the alignment increases. This patch moves the alignment calculation into the loop populating the controller entries, thus updating the alignment for each controller entry.
Quoted 6 lines
Signed-off-by Marek Vasut <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Lorenzo Pieralisi <[email protected]>Cc Wolfram Sang <[email protected]>
Quoted 54 lines
--- drivers/pci/controller/pcie-rcar.c | 33 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-)drivers/pci/controller/pcie-rcar.c +17
-16@@ -1029,25 +1029,26 @@ static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,if (restype &IORESOURCE_PREFETCH ) flags |=LAM_PREFETCH ; -/* -* If the size of the range is larger than the alignment of the start -* address, we have to use multiple entries to perform the mapping. -*/ -if (cpu_addr >0 ) { -unsigned long nr_zeros =__ffs64 (cpu_addr); -u64 alignment =1ULL << nr_zeros; +while (cpu_addr < cpu_end) { +/* +* If the size of the range is larger than the alignment of +* the start address, we have to use multiple entries to +* perform the mapping. +*/ +if (cpu_addr >0 ) { +unsigned long nr_zeros =__ffs64 (cpu_addr); +u64 alignment =1ULL << nr_zeros; - size =min (range->size, alignment); - }else { - size = range->size; - } -/* Hardware supports max 4GiB inbound region */ - size =min (size,1ULL <<32 ); + size =min (range->size, alignment); + }else { + size = range->size; + } +/* Hardware supports max 4GiB inbound region */ + size =min (size,1ULL <<32 ); - mask =roundup_pow_of_two (size) -1 ; - mask &= ~0xf ; + mask =roundup_pow_of_two (size) -1 ; + mask &= ~0xf ; -while (cpu_addr < cpu_end) {/* * Set up 64-bit inbound regions as the range parser doesn't * distinguish between 32 and 64-bit types. Signature · 1 line
2.20.1
Hi Marek,
Quoted 7 lines · On Tue, Jul 9, 2019 at 3:18 AM <[email protected]> wrote:
From: Marek Vasut <[email protected]>
In case the "dma-ranges" DT property contains either too many ranges or the range start address is unaligned in such a way that populating the range into the controller requires multiple entries, a situation may occur where all ranges cannot be loaded into the controller.
Quoted 5 lines
Currently, the driver refuses to probe in such a situation. Relax this behavior, load as many ranges as possible and warn if some ranges do not fit anymore.
Signed-off-by Marek Vasut <[email protected]>
Thanks for your patch!
Quoted 4 lines
drivers/pci/controller/pcie-rcar.c +0
-0@@ -1069,8 +1069,9 @@ static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie, idx +=2 ;
drivers/pci/controller/pcie-rcar.c static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie, · line 1077
Quoted 10 lines
drivers/pci/controller/pcie-rcar.c +3
-2if (idx >MAX_NR_INBOUND_MAPS ) { -dev_err (pcie->dev,"Failed to map inbound regions!\n" ); -return -EINVAL ; +dev_warn (pcie->dev, +"Too many inbound regions, not all are mapped.\n" ); +break ; } } *index = idx;
The incremented idx is stored here. Hence for each subsequent call to rcar_pcie_inbound_ranges() from the loop in rcar_pcie_parse_map_dma_ranges(), it will write to nonexisting registers.
It seems that can already happen now (but only for the last iteration, just before it errors out), so probably you want to fix that first, by moving the check to the start of the loop.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds