Skip to content

soc: arm: xilinx_zynq7000: add MMU PTEs for all AXI GPIO instances #46463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ibirnbaum
Copy link
Member

Add the MMU page table entries for all instances of the Xilinx AXI GPIO controller IP core. Other than any Zynq-7000 peripheral supported so far, the existance of 1..n instances of the IP core within the FPGA part of the SoC is optional. Therefore, other than addressing instances of supported peripherals using their DT nodelabel as has always been the case so far, the data for the MMU page table is added using the DT_FOREACH_STATUS_OKAY macro.

Signed-off-by: Immo Birnbaum [email protected]

Comment on lines 14 to 23
#define AXI_GPIO_MMU_ENTRY(id)\
MMU_REGION_FLAT_ENTRY("axigpio",\
DT_REG_ADDR(id),\
DT_REG_SIZE(id),\
MT_DEVICE | MATTR_SHARED | MPERM_R | MPERM_W),

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The driver should be refactored to use DEVICE_MMIO_ROM_INIT() instead.

@henrikbrixandersen
Copy link
Member

See #46477 for further discussions related to this.

Copy link
Collaborator

@carlocaione carlocaione left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, as @henrikbrixandersen said this should be really fixed at driver level by adding support for the MMIO APIs. The discussion in #46477 is really for ARM64 but the point is the same here.

@carlocaione carlocaione requested a review from microbuilder June 14, 2022 13:02
@ibirnbaum
Copy link
Member Author

ibirnbaum commented Jun 14, 2022

One point already mentioned in the discussion in #46477 is that the driver for which the [0..n] MMU entries are being added here is for a peripheral which exists both in the Zynq-7000, where the memory has to be mapped via the MMU, and in the UltraScale, which has the MPU. At the time being, all of the UltraScale's peripherals and the On-Chip Memory are covered by a single 128 MB R/W/nocache MPU region if the MPU is active, so there's nothing to do with regards to the UltraScale. If the driver was to be modified to use MMIO rather than having the MMU set up based on code outside of the driver, that would be SoC family-specific.

This issue basically affects all supported Xilinx peripherals: the AXI GPIO, the PS GPIO, the UART, the GEM, the CAN controller for which a driver has been submitted for review, and some others still in my pipeline (I2C, SPI, etc.).

@carlocaione
Copy link
Collaborator

If the driver was to be modified to use MMIO rather than having the MMU set up based on code outside of the driver, that would be SoC family-specific.

Why? The MMIO API is MMU mapping the addresses only when an MMU is present, see

#if defined(CONFIG_MMU) || defined(CONFIG_PCIE)
#define DEVICE_MMIO_IS_IN_RAM
#endif

In case of MPU, the API is simply falling back to access the usual address without mapping anything:

#ifdef DEVICE_MMIO_IS_IN_RAM
#define DEVICE_MMIO_MAP(dev, flags) \
device_map(DEVICE_MMIO_RAM_PTR(dev), \
DEVICE_MMIO_ROM_PTR(dev)->phys_addr, \
DEVICE_MMIO_ROM_PTR(dev)->size, \
(flags))
#else
#define DEVICE_MMIO_MAP(dev, flags) do { } while (0)
#endif

This issue basically affects all supported Xilinx peripherals: the AXI GPIO, the PS GPIO, the UART, the GEM, the CAN controller for which a driver has been submitted for review, and some others still in my pipeline (I2C, SPI, etc.).

Yeah this sucks. I'm trying to push for all the new drivers to support MMIO API as soon as they are introduced but I cannot push people to fix all the existing drivers, especially when there are a lot of them. So, I can approve this as workaround for an existing driver but if you are going to introduce new drivers these must support the MMIO API out-of-the-box.

@ibirnbaum
Copy link
Member Author

This issue basically affects all supported Xilinx peripherals: the AXI GPIO, the PS GPIO, the UART, the GEM, the CAN controller for which a driver has been submitted for review, and some others still in my pipeline (I2C, SPI, etc.).

Yeah this sucks. I'm trying to push for all the new drivers to support MMIO API as soon as they are introduced but I cannot push people to fix all the existing drivers, especially when there are a lot of them. So, I can approve this as workaround for an existing driver but if you are going to introduce new drivers these must support the MMIO API out-of-the-box.

I don't mind converting all the existing Xilinx drivers, that's something that shouldn't take too long, most of them should be fairly simple to switch over, and if memory areas like the SLCR and the MPCore registers can still be mapped via the mmu_regions table in future releases and DMA can still be set up as it currently is being set up in the GEM driver in future releases, there shouldn't be any major conflicts. What I was trying to point out was that if the memory mapping API wasn't compatible with non-MMU systems, some sort of SoC-specific adaptation would have been required for all the Xilinx drivers as the Zynq and the UltraScale support all those peripherals equally. As the physical address is returned by the API in the non-MMU scenario, that assumed issue doesn't exist. So I guess I'll get to it.

@ibirnbaum
Copy link
Member Author

@henrikbrixandersen @carlocaione I've had a go at refactoring the Xilinx AXI GPIO and PS GPIO drivers to use the MMIO API instead, but at the time being, it's just not possible to let GPIO drivers use the MMIO API due to conflicting demands - I opened #48243 to address the issue, as I don't think that having a hand full of particular device drivers or one class of device drivers use a workaround all the other drivers don't need is a good idea. Therefore, could we for now go ahead as suggested herein for now, until a clean solution is found? I'd really like to add support for the Zedboard, where unfortunately, most of the useful GPIOs (slider switches, buttons, LEDs) can only be connected to instances of the AXI GPIO IP core.

@carlocaione
Copy link
Collaborator

@ibirnbaum I'm fine to put aside the MMIO story but please fix the CI to be all green so I can take again another look.

@ibirnbaum
Copy link
Member Author

@carlocaione I'll force-push in order to run the CI again. During the last run, the completely unrelated test case net.socket.tcp failed on the unrelated target mps2_an385. Looks to me like a glitch of the CI itself?

…ances

add the MMU page table entries for all instances of the Xilinx AXI GPIO
controller IP core. Other than any Zynq-7000 peripheral supported so far,
the existance of 1..n instances of the IP core within the FPGA part of the
SoC is optional. Therefore, other than addressing instances of supported
peripherals using their DT node label as has always been the case so far,
the data for the MMU page table is added using the DT_FOREACH_STATUS_OKAY
macro.

Signed-off-by: Immo Birnbaum <[email protected]>
@ibirnbaum ibirnbaum force-pushed the xc7z_axi_gpio_mmu_ptes branch from d8d44bc to 595b5b7 Compare August 8, 2022 20:47
@ibirnbaum
Copy link
Member Author

@carlocaione CI passed this time as intended.

Copy link
Member

@henrikbrixandersen henrikbrixandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am okay with this work-around for now, but we really need to get this working for all kinds of peripherals (in-tree as well as out-of-tree).

If we re-organise the devicetree to closer match that of the Linux kernel (where all memory-mapped peripherals of the Zynq7000 are below an amba node) we should be able to iterate all these child devices and add corresponding MMU regions.

@fabiobaltieri fabiobaltieri merged commit 86d68e1 into zephyrproject-rtos:main Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants