On Thu, Dec 12, 2019 at 06:38:31AM +0100, Andreas Färber wrote: > Am 11.12.19 um 23:49 schrieb Paul Walmsley: > > On Wed, 11 Dec 2019, Andreas Färber wrote: > > > >> Blocks do have names, but they don't always group registers of the same > >> kind, as Linux expects it > > > > Linux does not expect that all of the registers in the same IP block are > > of the same kind. That's part of the reason why Linux frameworks exist. > > To consider clocks as the present example, you're welcome to register > > local IP block clock control registers in the local IP block driver via > > the clock framework. There's no need for a separate clock driver with an > > overlapping address range, or anything like that. > > If I throw random code into drivers/mfd/ it will not get proper review. I don't think that's what Paul was suggesting. MFD is something that can help in these cases, but often isn't required. > We rely on clk drivers going into drivers/clk/, even if I could > theoretically register clks also from other parts of the code base - > which will then require complex Kconfig dependencies or #ifdef'ery, not > to mention the nightmares of collecting Acks and figuring out through > whose tree which patches go. That's a process issue and isn't actually that bad in my experience. > > This is nothing new with Realtek. > > As this NXP patch proves. :) > > > IP blocks that contain many different > > kinds of registers have had Linux driver support without requiring > > overlapping register address ranges long before Realtek ARM SoCs > > appeared. > > Hey, you're the one that's trying to pin this on Realtek, not me! > STM32 RCC is another example I know, also Allwinner, etc. My point was > precisely that this is - for good or bad - a rather common scenario that > we need to deal with. > > >> Just please accept that hardware does not always allow for unique > >> contiguous memory reservations > > > > Hardware designs do in fact mandate unique contiguous memory reservations, > > otherwise address decoding would be indeterministic. > > Are you not understanding what I'm saying or intentionally gas-lighting? > A contiguous memory _reservation_ is a range of memory like <0xdead0000 > 0x100> that the kernel (software!) blocks other drivers (software!) from > reserving. This has _nothing_ to do with hardware address line decoding. > It's still about devm_platform_ioremap_resource() and related APIs. Do a > `cat /proc/iomem` to see, e.g., "98007800-9800781f : serial" reservation > in successful case; as mentioned by Leonard, an unsuccessful reservation > usually causes the driver to fail to probe and thus be unavailable. I think what Paul is saying here is that even in hardware you do in fact have these contiguous address regions assigned for each block. This is just because you need to have an address decoder somewhere that forwards addresses from the CPU to the various IP blocks. These address decoders work on contiguous ranges, so by definitions registers within the same region go to the same IP block. > > What they don't > > mandate is that all of the registers in that region be all of one kind. > > It's certainly possible to have an SoC with one giant IP block with all > > registers mixed together. Even in that case, it is still incorrect to > > have multiple DT entries with overlapping register address ranges. > > Says who? Since when? Can we maybe agree that incorrect != invalid? We always represent each hardware blocks with one device tree node. Given the above, if you have multiple nodes with overlapping register ranges, you're describing one hardware block with multiple nodes and that's when these kinds of issues come up. > > It sounds like you're thinking of the difficulties of figuring out how to > > structure the software driver support for those mixed IP block as a Linux > > driver: > > Yes, these are Linux kernel mailing lists and patches after all... I > don't design hardware, that's why I said we need to live with the flawed > reality of the actual hardware we get. I don't think the hardware is necessarily flawed. It might not be structured in a way that reflects the Linux kernel's subsystem structure, but that's quite common. That's not a problem to solve at the device tree level. The device tree should describe the hardware. It's the job of device drivers to make the hardware available to the kernel and its subsystems. > > where it would fit in the tree, what frameworks it would need to > > register with, and who would maintain it. Those issues certainly merit > > careful thought and consideration. They aren't related to multiple > > overlapping address ranges. > > Oh they are. Overlapping address ranges of DT nodes are a _result_ of > unexpected hardware design involving blocks not clearly separated the > same way as Linux subsystems (to distinguish from "frameworks") are. > > The DT should describe the hardware blocks as they were designed, but on > the other hand, we need to describe it in a way that Linux drivers can > actually bind against the relevant parts and that those drivers can > operate efficiently. That's exactly where the misconception is. DT should not at all be concerned about the operating system's internal structuring. While I think the way that Linux is structure is great, not all operating systems may work the same way. Other operating systems may not have separate frameworks for clocks and resets. So if you start writing device trees with a specific operating system in mind, you're likely going to end up with one device tree per device per operating system. That's not what we want. One device tree per device, independent of the operating system, that's the goal. > There is no ioremap-all-regs helper that I'm aware > of, for instance, as that would result in __iomem base addresses to be > stored per reg entry; compare that to just one for an overlapping range. > > Example: > > clk@f00 { > reg = <0xf00 0x100>; > } > > reset@f0f { > reg = <0xf0c 0x4>; > }; > > This should be a valid DT example today, as long as the clk driver > doesn't mess with the reset register embedded within its range. In this > case they can't both reserve their ranges as they would mutually cause > each other to fail to probe, depending on probe order. It's certainly not invalid DT from a syntax point of view. But that doesn't necessarily mean that it's a correct description of the hardware. > > As I wrote, turning this into > > clk@f00 { > reg = <0xf00 0xc>, <0xf10 0xe0>; > }; > > reset@f0f { > reg = <0xf0c 0x4>; > }; > > is helping no one and makes things much more complex, especially when > the number of carve-outs grows or is not predetermined, as I noted about > some of my cases. Thus I disagree with you about the overlapping ranges. Again, you're trying to split the hardware up based on Linux' frameworks rather than by the actual hardware blocks. > DT needs to be designed forward-looking rather than just around the > handful of registers we might read/write today, not just to relieve Rob > from excessive reviews. > > My solution was to do > > syscon@f00 { > reg = <0xf00 0x100>; > ranges = ...; > > clk@0 { > reg = <0x0 0x100>; > }; > > reset@c { > reg = <0xc 0x4>; > }; > }; That's starting to look more like it. But still, why even bother with the separate clk and reset nodes? This block clearly provides both controls for clocks and controls for resets. The fact that Linux has two separate frameworks for these types of resources is secondary. The right thing to do here is to have one driver for the whole block and then register its device with both the clock and reset frameworks. That way you don't need two separate nodes. You only have these nodes so that you can get two separate devices that a clock driver and a reset driver can bind to, respectively. There's nothing in the frameworks that would prevent the same driver from registering to both frameworks. In other words, it's perfectly fine to have a single device/driver be a clock provider and reset provider at the same time. > https://patchwork.kernel.org/cover/11269453/ > https://patchwork.kernel.org/cover/11269971/ (and more in my tree) > > which clearly models the blocks and shares a syscon for most children, > other than pre-existing 8250 UART, I²C, etc. drivers using platform > helpers such as the one discussed here. > > What we lose with syscon is reservations, i.e. /proc/iomem neither > showing the full syscon nor the drivers using parts of it, unless we > explicitly reserve the memory (syscon does the ioremap for us, so no > need for this devm_platform_ioremap_resource helper there). > > Also please keep in mind that we actually want to get to the point where > new systems are booting and usable. At least in the Arm world we do have > hardware at plenty to boot Linux. Dying in DT-beauty then is > counter-productive; we also need to come to timely compromises for not > blocking other work. clk drivers don't need to be platform_drivers like > here and thus can coexist easier with other drivers (e.g., syscon > without child), but I clearly contradict the generality in which you > appear to rule out overlapping memory ranges, be it for siblings or for > parent/child. I think the common misconception that we need separate drivers for each framework is what's counter-productive. If the same device provides different types of resources, then we should just have one driver register with whatever the frameworks are that expose these resources. It becomes really quite simple once you shed that misconception. Thierry > Hiding overlaps in an mfd driver does not strike me as better than > openly declaring them - if the mfd components are not dynamic, then I > understood simple-mfd were the way to go, which requires some reg(s), > which then for convenience may overlap if there's no clear boundaries. > > Regards, > Andreas > > -- > SUSE Software Solutions Germany GmbH > Maxfeldstr. 5, 90409 Nürnberg, Germany > GF: Felix Imendörffer > HRB 36809 (AG Nürnberg)