Message ID | 1588213867-32274-1-git-send-email-yangtiezhu@loongson.cn (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [v6] MIPS: Loongson: Add DMA support for LS7A | expand |
于 2020年4月30日 GMT+08:00 上午10:31:07, Tiezhu Yang <yangtiezhu@loongson.cn> 写到: >In the current market, the most used bridge chip on the Loongson >platform are RS780E and LS7A, the RS780E bridge chip is already >supported by the mainline kernel. > >In order to use the default implementation of __phys_to_dma() and >__dma_to_phys() in dma-direct.h, remove CONFIG_ARCH_HAS_PHYS_TO_DMA >and then set the bus's DMA limit to 36 bit for RS780E to maintain >downward compatibility. > >Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> >--- > >Hi Christoph and Jiaxun, > >Thank you very much for your suggestions. I'm probably going to refine this before we implement full devicetree boot, but that's in far future. LGTM to me for now. Thanks. Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com> > >v5: > - use the default implementation of __phys_to_dma() > and __dma_to_phys() in dma-direct.h > >v6: > - make loongson_dma_config() static > - put ls7a things before rs780 things > > arch/mips/Kconfig | 1 - > arch/mips/include/asm/mach-loongson64/boot_param.h | 5 +++++ > arch/mips/loongson64/dma.c | 22 +++++++++++----------- > arch/mips/loongson64/env.c | 2 ++ > 4 files changed, 18 insertions(+), 12 deletions(-) > >diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig >index 9f15539..12b6bdb 100644 >--- a/arch/mips/Kconfig >+++ b/arch/mips/Kconfig >@@ -1454,7 +1454,6 @@ choice > config CPU_LOONGSON64 > bool "Loongson 64-bit CPU" > depends on SYS_HAS_CPU_LOONGSON64 >- select ARCH_HAS_PHYS_TO_DMA > select CPU_MIPSR2 > select CPU_HAS_PREFETCH > select CPU_SUPPORTS_64BIT_KERNEL >diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h b/arch/mips/include/asm/mach-loongson64/boot_param.h >index f082d87..0c07a96 100644 >--- a/arch/mips/include/asm/mach-loongson64/boot_param.h >+++ b/arch/mips/include/asm/mach-loongson64/boot_param.h >@@ -197,6 +197,7 @@ enum loongson_bridge_type { > RS780E = 2 > }; > >+struct pci_dev; > struct loongson_system_configuration { > u32 nr_cpus; > u32 nr_nodes; >@@ -221,9 +222,13 @@ struct loongson_system_configuration { > u32 nr_sensors; > struct sensor_device sensors[MAX_SENSORS]; > u64 workarounds; >+ void (*dma_config)(struct pci_dev *pdev); > }; > > extern struct efi_memory_map_loongson *loongson_memmap; > extern struct loongson_system_configuration loongson_sysconf; > >+extern void ls7a_dma_config(struct pci_dev *pdev); >+extern void rs780e_dma_config(struct pci_dev *pdev); >+ > #endif >diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c >index 5e86635..ef40b0d 100644 >--- a/arch/mips/loongson64/dma.c >+++ b/arch/mips/loongson64/dma.c >@@ -1,24 +1,24 @@ > // SPDX-License-Identifier: GPL-2.0 >-#include <linux/dma-direct.h> >+#include <linux/pci.h> > #include <linux/init.h> > #include <linux/swiotlb.h> > >-dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr) >+void ls7a_dma_config(struct pci_dev *pdev) > { >- /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from >- * Loongson-3's 48bit address space and embed it into 40bit */ >- long nid = (paddr >> 44) & 0x3; >- return ((nid << 44) ^ paddr) | (nid << 37); > } > >-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr) >+void rs780e_dma_config(struct pci_dev *pdev) > { >- /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from >- * Loongson-3's 48bit address space and embed it into 40bit */ >- long nid = (daddr >> 37) & 0x3; >- return ((nid << 37) ^ daddr) | (nid << 44); >+ pdev->dev.bus_dma_limit = DMA_BIT_MASK(36); > } > >+static void loongson_dma_config(struct pci_dev *pdev) >+{ >+ loongson_sysconf.dma_config(pdev); >+} >+ >+DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, loongson_dma_config); >+ > void __init plat_swiotlb_setup(void) > { > swiotlb_init(1); >diff --git a/arch/mips/loongson64/env.c b/arch/mips/loongson64/env.c >index 71f4aaf..496f401 100644 >--- a/arch/mips/loongson64/env.c >+++ b/arch/mips/loongson64/env.c >@@ -192,8 +192,10 @@ void __init prom_init_env(void) > if (vendor == PCI_VENDOR_ID_LOONGSON && device == 0x7a00) { > pr_info("The bridge chip is LS7A\n"); > loongson_sysconf.bridgetype = LS7A; >+ loongson_sysconf.dma_config = ls7a_dma_config; > } else { > pr_info("The bridge chip is RS780E or SR5690\n"); > loongson_sysconf.bridgetype = RS780E; >+ loongson_sysconf.dma_config = rs780e_dma_config; > } > }
Hi Christoph, On Thu, Apr 30, 2020 at 10:31 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > In the current market, the most used bridge chip on the Loongson > platform are RS780E and LS7A, the RS780E bridge chip is already > supported by the mainline kernel. > > In order to use the default implementation of __phys_to_dma() and > __dma_to_phys() in dma-direct.h, remove CONFIG_ARCH_HAS_PHYS_TO_DMA > and then set the bus's DMA limit to 36 bit for RS780E to maintain > downward compatibility. I know that you want use the default implementation of __phys_to_dma() and __dma_to_phys() as more as possible. But, if that is "impossible" on Loongson-3, should we still be forced to use the default? Yes, this patch makes the default version work, but it limit the device's DMA capability, which is not what we want. > > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > --- > > Hi Christoph and Jiaxun, > > Thank you very much for your suggestions. > > v5: > - use the default implementation of __phys_to_dma() > and __dma_to_phys() in dma-direct.h > > v6: > - make loongson_dma_config() static > - put ls7a things before rs780 things > > arch/mips/Kconfig | 1 - > arch/mips/include/asm/mach-loongson64/boot_param.h | 5 +++++ > arch/mips/loongson64/dma.c | 22 +++++++++++----------- > arch/mips/loongson64/env.c | 2 ++ > 4 files changed, 18 insertions(+), 12 deletions(-) > > diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig > index 9f15539..12b6bdb 100644 > --- a/arch/mips/Kconfig > +++ b/arch/mips/Kconfig > @@ -1454,7 +1454,6 @@ choice > config CPU_LOONGSON64 > bool "Loongson 64-bit CPU" > depends on SYS_HAS_CPU_LOONGSON64 > - select ARCH_HAS_PHYS_TO_DMA > select CPU_MIPSR2 > select CPU_HAS_PREFETCH > select CPU_SUPPORTS_64BIT_KERNEL > diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h b/arch/mips/include/asm/mach-loongson64/boot_param.h > index f082d87..0c07a96 100644 > --- a/arch/mips/include/asm/mach-loongson64/boot_param.h > +++ b/arch/mips/include/asm/mach-loongson64/boot_param.h > @@ -197,6 +197,7 @@ enum loongson_bridge_type { > RS780E = 2 > }; > > +struct pci_dev; > struct loongson_system_configuration { > u32 nr_cpus; > u32 nr_nodes; > @@ -221,9 +222,13 @@ struct loongson_system_configuration { > u32 nr_sensors; > struct sensor_device sensors[MAX_SENSORS]; > u64 workarounds; > + void (*dma_config)(struct pci_dev *pdev); > }; > > extern struct efi_memory_map_loongson *loongson_memmap; > extern struct loongson_system_configuration loongson_sysconf; > > +extern void ls7a_dma_config(struct pci_dev *pdev); > +extern void rs780e_dma_config(struct pci_dev *pdev); > + > #endif > diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c > index 5e86635..ef40b0d 100644 > --- a/arch/mips/loongson64/dma.c > +++ b/arch/mips/loongson64/dma.c > @@ -1,24 +1,24 @@ > // SPDX-License-Identifier: GPL-2.0 > -#include <linux/dma-direct.h> > +#include <linux/pci.h> > #include <linux/init.h> > #include <linux/swiotlb.h> > > -dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr) > +void ls7a_dma_config(struct pci_dev *pdev) > { > - /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from > - * Loongson-3's 48bit address space and embed it into 40bit */ > - long nid = (paddr >> 44) & 0x3; > - return ((nid << 44) ^ paddr) | (nid << 37); > } > > -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr) > +void rs780e_dma_config(struct pci_dev *pdev) > { > - /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from > - * Loongson-3's 48bit address space and embed it into 40bit */ > - long nid = (daddr >> 37) & 0x3; > - return ((nid << 37) ^ daddr) | (nid << 44); > + pdev->dev.bus_dma_limit = DMA_BIT_MASK(36); > } > > +static void loongson_dma_config(struct pci_dev *pdev) > +{ > + loongson_sysconf.dma_config(pdev); > +} > + > +DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, loongson_dma_config); > + > void __init plat_swiotlb_setup(void) > { > swiotlb_init(1); > diff --git a/arch/mips/loongson64/env.c b/arch/mips/loongson64/env.c > index 71f4aaf..496f401 100644 > --- a/arch/mips/loongson64/env.c > +++ b/arch/mips/loongson64/env.c > @@ -192,8 +192,10 @@ void __init prom_init_env(void) > if (vendor == PCI_VENDOR_ID_LOONGSON && device == 0x7a00) { > pr_info("The bridge chip is LS7A\n"); > loongson_sysconf.bridgetype = LS7A; > + loongson_sysconf.dma_config = ls7a_dma_config; > } else { > pr_info("The bridge chip is RS780E or SR5690\n"); > loongson_sysconf.bridgetype = RS780E; > + loongson_sysconf.dma_config = rs780e_dma_config; > } > } > -- > 2.1.0 >
On 04/30/2020 02:19 PM, Huacai Chen wrote: > Hi Christoph, > > On Thu, Apr 30, 2020 at 10:31 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: >> In the current market, the most used bridge chip on the Loongson >> platform are RS780E and LS7A, the RS780E bridge chip is already >> supported by the mainline kernel. >> >> In order to use the default implementation of __phys_to_dma() and >> __dma_to_phys() in dma-direct.h, remove CONFIG_ARCH_HAS_PHYS_TO_DMA >> and then set the bus's DMA limit to 36 bit for RS780E to maintain >> downward compatibility. > I know that you want use the default implementation of __phys_to_dma() > and __dma_to_phys() as more as possible. But, if that is "impossible" > on Loongson-3, should we still be forced to use the default? Yes, this > patch makes the default version work, but it limit the device's DMA > capability, which is not what we want. Hi Huacai, We know that the AMD RS780E bridge chip has been discontinued for some years, as time goes by, it will gradually quit the stage of history. Today and in the future, the most popular used bridge chip on the Loongson platform is LS7A, so the initial aim of this patch is to add DMA support for LS7A, at the same time, we should maintain downward compatibility for RS780E. For the above reasons, I think what you are concerned is not a big deal. Thanks, Tiezhu Yang > >> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> >> --- >> >> Hi Christoph and Jiaxun, >> >> Thank you very much for your suggestions. >> >> v5: >> - use the default implementation of __phys_to_dma() >> and __dma_to_phys() in dma-direct.h >> >> v6: >> - make loongson_dma_config() static >> - put ls7a things before rs780 things >> >> arch/mips/Kconfig | 1 - >> arch/mips/include/asm/mach-loongson64/boot_param.h | 5 +++++ >> arch/mips/loongson64/dma.c | 22 +++++++++++----------- >> arch/mips/loongson64/env.c | 2 ++ >> 4 files changed, 18 insertions(+), 12 deletions(-) >> >> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig >> index 9f15539..12b6bdb 100644 >> --- a/arch/mips/Kconfig >> +++ b/arch/mips/Kconfig >> @@ -1454,7 +1454,6 @@ choice >> config CPU_LOONGSON64 >> bool "Loongson 64-bit CPU" >> depends on SYS_HAS_CPU_LOONGSON64 >> - select ARCH_HAS_PHYS_TO_DMA >> select CPU_MIPSR2 >> select CPU_HAS_PREFETCH >> select CPU_SUPPORTS_64BIT_KERNEL >> diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h b/arch/mips/include/asm/mach-loongson64/boot_param.h >> index f082d87..0c07a96 100644 >> --- a/arch/mips/include/asm/mach-loongson64/boot_param.h >> +++ b/arch/mips/include/asm/mach-loongson64/boot_param.h >> @@ -197,6 +197,7 @@ enum loongson_bridge_type { >> RS780E = 2 >> }; >> >> +struct pci_dev; >> struct loongson_system_configuration { >> u32 nr_cpus; >> u32 nr_nodes; >> @@ -221,9 +222,13 @@ struct loongson_system_configuration { >> u32 nr_sensors; >> struct sensor_device sensors[MAX_SENSORS]; >> u64 workarounds; >> + void (*dma_config)(struct pci_dev *pdev); >> }; >> >> extern struct efi_memory_map_loongson *loongson_memmap; >> extern struct loongson_system_configuration loongson_sysconf; >> >> +extern void ls7a_dma_config(struct pci_dev *pdev); >> +extern void rs780e_dma_config(struct pci_dev *pdev); >> + >> #endif >> diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c >> index 5e86635..ef40b0d 100644 >> --- a/arch/mips/loongson64/dma.c >> +++ b/arch/mips/loongson64/dma.c >> @@ -1,24 +1,24 @@ >> // SPDX-License-Identifier: GPL-2.0 >> -#include <linux/dma-direct.h> >> +#include <linux/pci.h> >> #include <linux/init.h> >> #include <linux/swiotlb.h> >> >> -dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr) >> +void ls7a_dma_config(struct pci_dev *pdev) >> { >> - /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from >> - * Loongson-3's 48bit address space and embed it into 40bit */ >> - long nid = (paddr >> 44) & 0x3; >> - return ((nid << 44) ^ paddr) | (nid << 37); >> } >> >> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr) >> +void rs780e_dma_config(struct pci_dev *pdev) >> { >> - /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from >> - * Loongson-3's 48bit address space and embed it into 40bit */ >> - long nid = (daddr >> 37) & 0x3; >> - return ((nid << 37) ^ daddr) | (nid << 44); >> + pdev->dev.bus_dma_limit = DMA_BIT_MASK(36); >> } >> >> +static void loongson_dma_config(struct pci_dev *pdev) >> +{ >> + loongson_sysconf.dma_config(pdev); >> +} >> + >> +DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, loongson_dma_config); >> + >> void __init plat_swiotlb_setup(void) >> { >> swiotlb_init(1); >> diff --git a/arch/mips/loongson64/env.c b/arch/mips/loongson64/env.c >> index 71f4aaf..496f401 100644 >> --- a/arch/mips/loongson64/env.c >> +++ b/arch/mips/loongson64/env.c >> @@ -192,8 +192,10 @@ void __init prom_init_env(void) >> if (vendor == PCI_VENDOR_ID_LOONGSON && device == 0x7a00) { >> pr_info("The bridge chip is LS7A\n"); >> loongson_sysconf.bridgetype = LS7A; >> + loongson_sysconf.dma_config = ls7a_dma_config; >> } else { >> pr_info("The bridge chip is RS780E or SR5690\n"); >> loongson_sysconf.bridgetype = RS780E; >> + loongson_sysconf.dma_config = rs780e_dma_config; >> } >> } >> -- >> 2.1.0 >>
Hi, Tiezhu, On Wed, May 6, 2020 at 2:39 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > On 04/30/2020 02:19 PM, Huacai Chen wrote: > > Hi Christoph, > > > > On Thu, Apr 30, 2020 at 10:31 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > >> In the current market, the most used bridge chip on the Loongson > >> platform are RS780E and LS7A, the RS780E bridge chip is already > >> supported by the mainline kernel. > >> > >> In order to use the default implementation of __phys_to_dma() and > >> __dma_to_phys() in dma-direct.h, remove CONFIG_ARCH_HAS_PHYS_TO_DMA > >> and then set the bus's DMA limit to 36 bit for RS780E to maintain > >> downward compatibility. > > I know that you want use the default implementation of __phys_to_dma() > > and __dma_to_phys() as more as possible. But, if that is "impossible" > > on Loongson-3, should we still be forced to use the default? Yes, this > > patch makes the default version work, but it limit the device's DMA > > capability, which is not what we want. > > Hi Huacai, > > We know that the AMD RS780E bridge chip has been discontinued for > some years, as time goes by, it will gradually quit the stage of > history. > > Today and in the future, the most popular used bridge chip on the > Loongson platform is LS7A, so the initial aim of this patch is to > add DMA support for LS7A, at the same time, we should maintain > downward compatibility for RS780E. > > For the above reasons, I think what you are concerned is not a > big deal. I don't think so, this is obviously a regression. If we can accept a regression of RS780E, why we still maintain Loongson-2EF rather than simply drop them? > > Thanks, > Tiezhu Yang > > > > >> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > >> --- > >> > >> Hi Christoph and Jiaxun, > >> > >> Thank you very much for your suggestions. > >> > >> v5: > >> - use the default implementation of __phys_to_dma() > >> and __dma_to_phys() in dma-direct.h > >> > >> v6: > >> - make loongson_dma_config() static > >> - put ls7a things before rs780 things > >> > >> arch/mips/Kconfig | 1 - > >> arch/mips/include/asm/mach-loongson64/boot_param.h | 5 +++++ > >> arch/mips/loongson64/dma.c | 22 +++++++++++----------- > >> arch/mips/loongson64/env.c | 2 ++ > >> 4 files changed, 18 insertions(+), 12 deletions(-) > >> > >> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig > >> index 9f15539..12b6bdb 100644 > >> --- a/arch/mips/Kconfig > >> +++ b/arch/mips/Kconfig > >> @@ -1454,7 +1454,6 @@ choice > >> config CPU_LOONGSON64 > >> bool "Loongson 64-bit CPU" > >> depends on SYS_HAS_CPU_LOONGSON64 > >> - select ARCH_HAS_PHYS_TO_DMA > >> select CPU_MIPSR2 > >> select CPU_HAS_PREFETCH > >> select CPU_SUPPORTS_64BIT_KERNEL > >> diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h b/arch/mips/include/asm/mach-loongson64/boot_param.h > >> index f082d87..0c07a96 100644 > >> --- a/arch/mips/include/asm/mach-loongson64/boot_param.h > >> +++ b/arch/mips/include/asm/mach-loongson64/boot_param.h > >> @@ -197,6 +197,7 @@ enum loongson_bridge_type { > >> RS780E = 2 > >> }; > >> > >> +struct pci_dev; > >> struct loongson_system_configuration { > >> u32 nr_cpus; > >> u32 nr_nodes; > >> @@ -221,9 +222,13 @@ struct loongson_system_configuration { > >> u32 nr_sensors; > >> struct sensor_device sensors[MAX_SENSORS]; > >> u64 workarounds; > >> + void (*dma_config)(struct pci_dev *pdev); > >> }; > >> > >> extern struct efi_memory_map_loongson *loongson_memmap; > >> extern struct loongson_system_configuration loongson_sysconf; > >> > >> +extern void ls7a_dma_config(struct pci_dev *pdev); > >> +extern void rs780e_dma_config(struct pci_dev *pdev); > >> + > >> #endif > >> diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c > >> index 5e86635..ef40b0d 100644 > >> --- a/arch/mips/loongson64/dma.c > >> +++ b/arch/mips/loongson64/dma.c > >> @@ -1,24 +1,24 @@ > >> // SPDX-License-Identifier: GPL-2.0 > >> -#include <linux/dma-direct.h> > >> +#include <linux/pci.h> > >> #include <linux/init.h> > >> #include <linux/swiotlb.h> > >> > >> -dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr) > >> +void ls7a_dma_config(struct pci_dev *pdev) > >> { > >> - /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from > >> - * Loongson-3's 48bit address space and embed it into 40bit */ > >> - long nid = (paddr >> 44) & 0x3; > >> - return ((nid << 44) ^ paddr) | (nid << 37); > >> } > >> > >> -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr) > >> +void rs780e_dma_config(struct pci_dev *pdev) > >> { > >> - /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from > >> - * Loongson-3's 48bit address space and embed it into 40bit */ > >> - long nid = (daddr >> 37) & 0x3; > >> - return ((nid << 37) ^ daddr) | (nid << 44); > >> + pdev->dev.bus_dma_limit = DMA_BIT_MASK(36); > >> } > >> > >> +static void loongson_dma_config(struct pci_dev *pdev) > >> +{ > >> + loongson_sysconf.dma_config(pdev); > >> +} > >> + > >> +DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, loongson_dma_config); > >> + > >> void __init plat_swiotlb_setup(void) > >> { > >> swiotlb_init(1); > >> diff --git a/arch/mips/loongson64/env.c b/arch/mips/loongson64/env.c > >> index 71f4aaf..496f401 100644 > >> --- a/arch/mips/loongson64/env.c > >> +++ b/arch/mips/loongson64/env.c > >> @@ -192,8 +192,10 @@ void __init prom_init_env(void) > >> if (vendor == PCI_VENDOR_ID_LOONGSON && device == 0x7a00) { > >> pr_info("The bridge chip is LS7A\n"); > >> loongson_sysconf.bridgetype = LS7A; > >> + loongson_sysconf.dma_config = ls7a_dma_config; > >> } else { > >> pr_info("The bridge chip is RS780E or SR5690\n"); > >> loongson_sysconf.bridgetype = RS780E; > >> + loongson_sysconf.dma_config = rs780e_dma_config; > >> } > >> } > >> -- > >> 2.1.0 > >> >
On Wed, May 06, 2020 at 04:47:30PM +0800, Huacai Chen wrote: > > For the above reasons, I think what you are concerned is not a > > big deal. > I don't think so, this is obviously a regression. If we can accept a > regression of RS780E, why we still maintain Loongson-2EF rather than > simply drop them? While I much prefer to use the default, regression an otherwise working platform seems like a bad idea. I don't really know much about the Loongson platforms, do they all boot using the same kernel image?
Hi, Christoph, On Wed, May 6, 2020 at 10:44 PM Christoph Hellwig <hch@infradead.org> wrote: > > On Wed, May 06, 2020 at 04:47:30PM +0800, Huacai Chen wrote: > > > For the above reasons, I think what you are concerned is not a > > > big deal. > > I don't think so, this is obviously a regression. If we can accept a > > regression of RS780E, why we still maintain Loongson-2EF rather than > > simply drop them? > > While I much prefer to use the default, regression an otherwise > working platform seems like a bad idea. I don't really know much > about the Loongson platforms, do they all boot using the same kernel > image? All Loongson-3 machines (with LS7A bridge or RS780 bridge) use the same kernel image.
On 05/07/2020 09:41 AM, Huacai Chen wrote: > Hi, Christoph, > > On Wed, May 6, 2020 at 10:44 PM Christoph Hellwig <hch@infradead.org> wrote: >> On Wed, May 06, 2020 at 04:47:30PM +0800, Huacai Chen wrote: >>>> For the above reasons, I think what you are concerned is not a >>>> big deal. >>> I don't think so, this is obviously a regression. If we can accept a >>> regression of RS780E, why we still maintain Loongson-2EF rather than >>> simply drop them? >> While I much prefer to use the default, regression an otherwise >> working platform seems like a bad idea. I don't really know much >> about the Loongson platforms, do they all boot using the same kernel >> image? > All Loongson-3 machines (with LS7A bridge or RS780 bridge) use the > same kernel image. Hi Christoph, Huacai and Jiaxun, Thank you very much for your reviews and discussions. If you agree to use the platform dependent implementation of __phys_to_dma() and __dma_to_phys(), I will make a slight modification based on the v4 patch [1] to put ls7a things before rs780e things, and then send v7 as soon as possible. If anyone has any objections, please let me know. [1] https://lore.kernel.org/patchwork/patch/1220010/ Thanks, Tiezhu Yang
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 9f15539..12b6bdb 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -1454,7 +1454,6 @@ choice config CPU_LOONGSON64 bool "Loongson 64-bit CPU" depends on SYS_HAS_CPU_LOONGSON64 - select ARCH_HAS_PHYS_TO_DMA select CPU_MIPSR2 select CPU_HAS_PREFETCH select CPU_SUPPORTS_64BIT_KERNEL diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h b/arch/mips/include/asm/mach-loongson64/boot_param.h index f082d87..0c07a96 100644 --- a/arch/mips/include/asm/mach-loongson64/boot_param.h +++ b/arch/mips/include/asm/mach-loongson64/boot_param.h @@ -197,6 +197,7 @@ enum loongson_bridge_type { RS780E = 2 }; +struct pci_dev; struct loongson_system_configuration { u32 nr_cpus; u32 nr_nodes; @@ -221,9 +222,13 @@ struct loongson_system_configuration { u32 nr_sensors; struct sensor_device sensors[MAX_SENSORS]; u64 workarounds; + void (*dma_config)(struct pci_dev *pdev); }; extern struct efi_memory_map_loongson *loongson_memmap; extern struct loongson_system_configuration loongson_sysconf; +extern void ls7a_dma_config(struct pci_dev *pdev); +extern void rs780e_dma_config(struct pci_dev *pdev); + #endif diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c index 5e86635..ef40b0d 100644 --- a/arch/mips/loongson64/dma.c +++ b/arch/mips/loongson64/dma.c @@ -1,24 +1,24 @@ // SPDX-License-Identifier: GPL-2.0 -#include <linux/dma-direct.h> +#include <linux/pci.h> #include <linux/init.h> #include <linux/swiotlb.h> -dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr) +void ls7a_dma_config(struct pci_dev *pdev) { - /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from - * Loongson-3's 48bit address space and embed it into 40bit */ - long nid = (paddr >> 44) & 0x3; - return ((nid << 44) ^ paddr) | (nid << 37); } -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr) +void rs780e_dma_config(struct pci_dev *pdev) { - /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from - * Loongson-3's 48bit address space and embed it into 40bit */ - long nid = (daddr >> 37) & 0x3; - return ((nid << 37) ^ daddr) | (nid << 44); + pdev->dev.bus_dma_limit = DMA_BIT_MASK(36); } +static void loongson_dma_config(struct pci_dev *pdev) +{ + loongson_sysconf.dma_config(pdev); +} + +DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, loongson_dma_config); + void __init plat_swiotlb_setup(void) { swiotlb_init(1); diff --git a/arch/mips/loongson64/env.c b/arch/mips/loongson64/env.c index 71f4aaf..496f401 100644 --- a/arch/mips/loongson64/env.c +++ b/arch/mips/loongson64/env.c @@ -192,8 +192,10 @@ void __init prom_init_env(void) if (vendor == PCI_VENDOR_ID_LOONGSON && device == 0x7a00) { pr_info("The bridge chip is LS7A\n"); loongson_sysconf.bridgetype = LS7A; + loongson_sysconf.dma_config = ls7a_dma_config; } else { pr_info("The bridge chip is RS780E or SR5690\n"); loongson_sysconf.bridgetype = RS780E; + loongson_sysconf.dma_config = rs780e_dma_config; } }
In the current market, the most used bridge chip on the Loongson platform are RS780E and LS7A, the RS780E bridge chip is already supported by the mainline kernel. In order to use the default implementation of __phys_to_dma() and __dma_to_phys() in dma-direct.h, remove CONFIG_ARCH_HAS_PHYS_TO_DMA and then set the bus's DMA limit to 36 bit for RS780E to maintain downward compatibility. Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> --- Hi Christoph and Jiaxun, Thank you very much for your suggestions. v5: - use the default implementation of __phys_to_dma() and __dma_to_phys() in dma-direct.h v6: - make loongson_dma_config() static - put ls7a things before rs780 things arch/mips/Kconfig | 1 - arch/mips/include/asm/mach-loongson64/boot_param.h | 5 +++++ arch/mips/loongson64/dma.c | 22 +++++++++++----------- arch/mips/loongson64/env.c | 2 ++ 4 files changed, 18 insertions(+), 12 deletions(-)