Inspiration for this comes from: http://www.mail-archive.com/linux-omap@vger.kernel.org/msg31161.html INTRO As SOCs become more popular, the desire to quickly define a simple, but functional, bus type with only a few unique properties becomes desirable. As they become more complicated, the ability to nest these simple busses and otherwise orchestrate them to match the actual topology also becomes desirable. EXAMPLE USAGE /arch/ARCH/MY_ARCH/my_bus.c: #include <linux/device.h> #include <linux/platform_device.h> struct bus_type my_bus_type = { .name = "mybus", }; EXPORT_SYMBOL_GPL(my_bus_type); struct platform_device sub_bus1 = { .name = "sub_bus1", .id = -1, .dev.bus = &my_bus_type, } EXPORT_SYMBOL_GPL(sub_bus1); struct platform_device sub_bus2 = { .name = "sub_bus2", .id = -1, .dev.bus = &my_bus_type, } EXPORT_SYMBOL_GPL(sub_bus2); static int __init my_bus_init(void) { int error; platform_bus_type_init(&my_bus_type); error = bus_register(&my_bus_type); if (error) return error; error = platform_device_register(&sub_bus1); if (error) goto fail_sub_bus1; error = platform_device_register(&sub_bus2); if (error) goto fail_sub_bus2; return error; fail_sub_bus2: platform_device_unregister(&sub_bus1); fail_sub_bus2: bus_unregister(&my_bus_type); return error; } postcore_initcall(my_bus_init); EXPORT_SYMBOL_CPY(my_bus_init); /drivers/my_driver.c static struct platform_driver my_driver = { .driver = { .name = "my-driver", .owner = THIS_MODULE, .bus = &my_bus_type, }, }; /somewhere/my_device.c static struct platform_device my_device = { .name = "my-device", .id = -1, .dev.bus = &my_bus_type, .dev.parent = &sub_bus_1.dev, }; Notice that for a device / driver, only 3 lines were added to switch from the platform bus to the new my_bus. This is especially valuable if we consider supporting a legacy SOCs and new SOCs where the same ...
Mis-typed omap's list; sorry for the resend -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum --
You really want a bus hanging off of a bus? Normally you need a device to do that, which is what I think you have here, but the naming is a bit odd to me. What would you do with this "sub bus"? It's just a device, but you are Ah, you put devices on this "sub bus". But why? Why not just put it on your "normal" bus that you created? What's with the extra level of nesting here? Other than that, it looks like a nice idea, are there portions of kernel Watch out for things in "write only" memory here. That could cause problems. thanks, greg k-h --
It's for power management stuff, basically, there are actual physical buses involved that can be completely powered off IFF all of their devices are Probably; right now this will always work since anything that is a platform_driver will have .driver.bus = &platform_bus_type, but that does change with this patch. Pardon my ignorance (I'm quite new to kernel work), what do you mean -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum --
For your question below, this could be in write-only memory. Well, I guess it never is as we modify things in the bus structure, so nevermind Then create a real bus hanging off of a device, not another device that See above. I was thinking that struct bus would be a constant or something. Sorry. greg k-h --
The motivation for doing it this was is that one driver could drive devices on two different subbusses. In the example, "my-driver" could drive a device on sub_bus1 AND sub_bus2 (if there were 2+ devices, one or more on each bus). From my understanding, this is not possible if they are actually different busses. --
This could be quite useful on the Qualcomm devices where there are many collections of "devices" that resemble a bus but cannot be directly enumerated but are initialized by platform code or possibly in future, a device tree. One such bus is made up of SMI devices that are identified to the applications core by the modem firmware and can be in the form of character devices (smd), network devices (rmnet) rpc router channel and others, we also have to deal with the MDDI video bus which represented a challenge when migrating the HTC Rhodium to 2.6.32 as each mdp device (and others in later kernels) are added to the platform bus dynamically, though they don't appear similararly group in sysfs due to not actaully being on a bus. While it would have been possible to implement an mddi bus, the work would have essentially recreated the platform bus with a new name. A simliar challenge exists for exposing rpc endpoints to userspace as the current codebase uses character devices rather than introducing a new network protocol to the kernel, if such as bus was exposed through sysfs a userspace daemon could easily bind a GPS library to the PDAPI endpoint or similar features requiring less configuration to adapt to new AMSS firmware or device name layout. Thank you, Timothy Meade tmzt #htc-linux facebook.com/HTCLinux --
If we sat them at the "root", there would be a bunch of them there. I don't know, we could drop the parent, I guess whoever created the platform device oh so long ago, decided that it would look nicer to be I totally agree, and thanks for the detailed explaination, it saved me from having to write up the same thing :) greg k-h --
Personally I'd rather see a meaningful structure used here. Maybe having them all in the root will encourage people to find realistic parents for their platform devices. :-) Why don't I float a patch to remove this and see if anybody freaks out. Should I wrap it with a CONFIG_ so that it can be configurable for a release or to, or just -- Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. --
That would be nice, but take your "standard" PC today: > ls /sys/devices/platform/ Fixed MDIO bus.0 i8042 pcspkr power serial8250 uevent vesafb.0 There are tty devices below the serial port, which is nice to see, but If you can figure out a structure for the desktop/server machines, sure, I say just always enable it :) thanks, greg k-h --
Does it matter? On my PC I count 7 devices. On my servers, I see the same. I don't personally don't see any disadvantage to having them at the root. However, looking at them: "Fixed MDIO bus" is actually a complete hack that I'm going to try and get rid of. i8042 is keyboard/mouse that probably lives on the southbridge. I imagine hanging off the PCI bus in the ISA IO range. ditto pcspkr ditto serial8250 ditto vesafb I wouldn't have any problem modifying those specific drivers to register under something like /sys/devices/legacy, but I don't really think it is in any way necessary. I suppose one *could* try to figure out the actual PCI topology that leads to these devices, but that gets into trying to guess what the BIOS set up to decide where to register those things. Probably a lot of error-prone work for absolutely no benefit. :-) However, on the embedded side I'm seeing a lot of devices show up under /sys/devices/platform. Embedded is generally different. We *know* what the bus topology is. However, it seems to me that many developers are under the mistaken assumption that platform devices must live in /sys/devices/platform, so they don't bother reflecting the topology in the device model and it seems to be affecting how embedded PM is being approached (my opinion). Removing the "struct I've got a patch in my tree now. I'll play with it a bit before posting it for RFC. g. --
Or for that matter, make those drivers explicitly use /sys/devices/platform so that I don't cause churn on PCs. :-) I'd like to be rid of it as default behaviour for embedded though. g. --
Yes, that would be the easier (and better) solution. thanks, greg k-h --
Yes, I agree. This chunk makes sense independently of the rest of the patch. g. --
At compile time. I suspect there is an argument for having an "ANY_BUS_TYPE" value for the devices so that you can runtime wildcard It's exactly what I need to tidy up the SCU IPC devices on the new Intel MID platforms certainly. It's also a very small patch to achieve it Alan --
