On Mon, Oct 04, 2021 at 05:04:11PM +0200, Mark Kettenis wrote: > > Date: Mon, 4 Oct 2021 13:42:48 +0000 > > From: Visa Hankala <v...@hankala.org> > > > > On the Zynq-7000, the lowest 512KiB of physical address space usually > > contains RAM that is usable by the CPUs. However, many other bus > > masters, such as the Ethernet and SDIO controllers, are not able to > > access the 256KiB range that starts at physical address 0x40000. > > > > So far I have used a device tree that says that RAM starts at 0x80000, > > to avoid the DMA hole. This is unconventional, though. Typically the > > memory node for Zynq-7000 specifies 0x0 as the starting address for RAM. > > > > I think armv7 DMA constraint should be adjusted on the Zynq-7000 so that > > less device tree customization would be needed. > > > > This diff makes armv7 efiboot and kernel handle the > > openbsd,dma-constraint device tree property, with a tweak for the Zynq. > > The code is similar to what is already present on arm64 and riscv64. > > > > OK? > > Hmm. How does Linux know it can't do DMA to that memory range? > Normally that is done through a dma-ranges property in the device > tree, and my idea has always been to add code to parse these > properties to determine the valid DMA constraints. The reason there > is special code for the rpi4 is because the initial device trees for > the rpi4 didn't have those dma-ranges properties.
Linux reserves the first 512KiB in Zynq platform init code to prevent the region from being used. > I'm not necessarily against this diff going in, just curious if there > is a better way. > > > Index: arch/armv7/armv7/armv7_machdep.c > > =================================================================== > > RCS file: src/sys/arch/armv7/armv7/armv7_machdep.c,v > > retrieving revision 1.63 > > diff -u -p -r1.63 armv7_machdep.c > > --- arch/armv7/armv7/armv7_machdep.c 25 Mar 2021 04:12:01 -0000 > > 1.63 > > +++ arch/armv7/armv7/armv7_machdep.c 4 Oct 2021 13:32:11 -0000 > > @@ -453,6 +453,12 @@ initarm(void *arg0, void *arg1, void *ar > > len = fdt_node_property(node, "openbsd,uefi-mmap-desc-ver", > > &prop); > > if (len == sizeof(mmap_desc_ver)) > > mmap_desc_ver = bemtoh32((uint32_t *)prop); > > + > > + len = fdt_node_property(node, "openbsd,dma-constraint", &prop); > > + if (len == sizeof(uint64_t[2])) { > > + dma_constraint.ucr_low = bemtoh64((uint64_t *)prop); > > + dma_constraint.ucr_high = bemtoh64((uint64_t *)prop + > > 1); > > + } > > } > > > > process_kernel_args(); > > Index: arch/armv7/stand/efiboot/conf.c > > =================================================================== > > RCS file: src/sys/arch/armv7/stand/efiboot/conf.c,v > > retrieving revision 1.31 > > diff -u -p -r1.31 conf.c > > --- arch/armv7/stand/efiboot/conf.c 10 Jun 2021 22:17:58 -0000 1.31 > > +++ arch/armv7/stand/efiboot/conf.c 4 Oct 2021 13:32:11 -0000 > > @@ -42,7 +42,7 @@ > > #include "efidev.h" > > #include "efipxe.h" > > > > -const char version[] = "1.18"; > > +const char version[] = "1.19"; > > int debug = 0; > > > > struct fs_ops file_system[] = { > > Index: arch/armv7/stand/efiboot/efiboot.c > > =================================================================== > > RCS file: src/sys/arch/armv7/stand/efiboot/efiboot.c,v > > retrieving revision 1.34 > > diff -u -p -r1.34 efiboot.c > > --- arch/armv7/stand/efiboot/efiboot.c 7 Jun 2021 21:18:31 -0000 > > 1.34 > > +++ arch/armv7/stand/efiboot/efiboot.c 4 Oct 2021 13:32:11 -0000 > > @@ -435,6 +435,28 @@ efi_framebuffer(void) > > sizeof(framebuffer_path)); > > } > > > > +uint64_t dma_constraint[2] = { 0, -1 }; > > + > > +void > > +efi_dma_constraint(void) > > +{ > > + void *node; > > + > > + /* Raspberry Pi 4 is "special". */ > > + node = fdt_find_node("/"); > > + if (fdt_node_is_compatible(node, "brcm,bcm2711")) > > + dma_constraint[1] = htobe64(0x3bffffff); > > + > > + /* Not all bus masters can access 0x40000-0x7ffff on Zynq-7000. */ Even range 0x0-0x3ffff has fine print on it, so I will change the above comment to: /* Not all bus masters can access 0x0-0x7ffff on Zynq-7000. */ > > + if (fdt_node_is_compatible(node, "xlnx,zynq-7000")) > > + dma_constraint[0] = htobe64(0x00080000); > > + > > + /* Pass DMA constraint. */ > > + node = fdt_find_node("/chosen"); > > + fdt_node_add_property(node, "openbsd,dma-constraint", > > + dma_constraint, sizeof(dma_constraint)); > > +} > > + > > void > > efi_console(void) > > { > > @@ -515,6 +537,7 @@ efi_makebootargs(char *bootargs, int how > > > > efi_framebuffer(); > > efi_console(); > > + efi_dma_constraint(); > > > > fdt_finalize(); > > > > > > >