axi: add AXI bus driver
RFC PATCH v3 1/1 axi: add AXI bus driver
---
V2: Rename to axi
Use DEFINE_PCI_DEVICE_TABLE in bridge
Make use of pr_fmt and pr_*
Store core class
Rename bridge to not b43 specific
Replace magic 0x1000 with BCMAI_CORE_SIZE Remove some old "ssb" names and defines
Move BCMAI_ADDR_BASE def
Add drvdata field
V3: Fix reloading (kfree issue)
Add 14e4:4331
Fix non-initialized struct issue
Drop useless inline functions wrappers for pci core drv Proper pr_* usage
Helps in Kconfig
--- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/axi/Kconfig | 33 +++ drivers/axi/Makefile | 7 + drivers/axi/TODO | 3 + drivers/axi/axi_pci_bridge.c | 34 +++ drivers/axi/axi_private.h | 45 ++++ drivers/axi/core.c | 52 ++++ drivers/axi/driver_chipcommon.c | 87 +++++++ drivers/axi/driver_chipcommon_pmu.c | 134 ++++++++++ drivers/axi/driver_pci.c | 167 ++++++++++++ drivers/axi/host_pci.c | 177 +++++++++++++ drivers/axi/main.c | 256 +++++++++++++++++++ drivers/axi/scan.c | 393 +++++++++++++++++++++++++++++ drivers/axi/scan.h | 56 ++++ include/linux/axi/axi.h | 221 ++++++++++++++++ include/linux/axi/axi_driver_chipcommon.h | 308 ++++++++++++++++++++++ include/linux/axi/axi_driver_pci.h | 89 +++++++ include/linux/axi/axi_regs.h | 34 +++ include/linux/mod_devicetable.h | 17 ++ scripts/mod/file2alias.c | 21 ++ 21 files changed, 2137 insertions(+), 0 deletions(-) create mode 100644 drivers/axi/Kconfig create mode 100644 drivers/axi/Makefile create mode 100644 drivers/axi/TODO create mode 100644 drivers/axi/axi_pci_bridge.c create mode 100644 drivers/axi/axi_private.h create mode 100644 drivers/axi/core.c create mode 100644 drivers/axi/driver_chipcommon.c create mode 100644 drivers/axi/driver_chipcommon_pmu.c create mode 100644 drivers/axi/driver_pci.c create mode 100644 drivers/axi/host_pci.c create mode 100644 drivers/axi/main.c create mode 100644 drivers/axi/scan.c create mode 100644 drivers/axi/scan.h create mode 100644 include/linux/axi/axi.h create mode 100644 include/linux/axi/axi_driver_chipcommon.h create mode 100644 include/linux/axi/axi_driver_pci.h create mode 100644 include/linux/axi/axi_regs.h
drivers/Kconfig +2 -0
@@ -68,6 +68,8 @@ source "drivers/watchdog/Kconfig" source "drivers/ssb/Kconfig" +source "drivers/axi/Kconfig" + source "drivers/mfd/Kconfig" source "drivers/regulator/Kconfig"
drivers/Makefile +1 -0
@@ -110,6 +110,7 @@ obj-$(CONFIG_HID) += hid/ obj-$(CONFIG_PPC_PS3) += ps3/ obj-$(CONFIG_OF) += of/ obj-$(CONFIG_SSB) += ssb/ +obj-$(CONFIG_AXI) += axi/ obj-$(CONFIG_VHOST_NET) += vhost/ obj-$(CONFIG_VLYNQ) += vlynq/ obj-$(CONFIG_STAGING) += staging/
drivers/axi/Kconfig new file +33 -0
@@ -0,0 +1,33 @@ +config AXI_POSSIBLE + bool + depends on HAS_IOMEM && HAS_DMA + default y + +menu "AMBA AXI" + depends on AXI_POSSIBLE + +config AXI + tristate "AXI support" + depends on AXI_POSSIBLE + help + Bus driver for one of the Advanced Microcontroller Bus Architecture + interfaces: Advanced eXtensible Interface. + +config AXI_HOST_PCI_POSSIBLE + bool + depends on AXI && PCI = y + default y + +config AXI_HOST_PCI + bool "Support for AXI on PCI-host bus" + depends on AXI_HOST_PCI_POSSIBLE + +config AXI_DEBUG + bool "AXI debugging" + depends on AXI + help + This turns on additional debugging messages. + + If unsure, say N + +endmenu
drivers/axi/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +axi-y += main.o scan.o core.o +axi-y += driver_chipcommon.o driver_chipcommon_pmu.o +axi-y += driver_pci.o +axi-$(CONFIG_AXI_HOST_PCI) += host_pci.o axi_pci_bridge.o +obj-$(CONFIG_AXI) += axi.o + +ccflags-$(CONFIG_AXI_DEBUG) := -DDEBUG
drivers/axi/TODO new file +3 -0
@@ -0,0 +1,3 @@ +- Interrupts +- Documentation/ABI/README entry for new sysfs files +- Defines for PCI core driver
drivers/axi/axi_pci_bridge.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* AXI PCI bridge module +* +* Licensed under the GNU/GPL. See COPYING for details. +*/ + +#include "axi_private.h" + +#include <linux/axi/axi.h> +#include <linux/axi/axi_regs.h> +#include <linux/pci.h> + +static DEFINE_PCI_DEVICE_TABLE (axi_pci_bridge_tbl) = { + {PCI_DEVICE (PCI_VENDOR_ID_BROADCOM ,0x4331 ) }, + {PCI_DEVICE (PCI_VENDOR_ID_BROADCOM ,0x4353 ) }, + {PCI_DEVICE (PCI_VENDOR_ID_BROADCOM ,0x4727 ) }, + {0 , }, +}; +MODULE_DEVICE_TABLE (pci, axi_pci_bridge_tbl); + +static struct pci_driver axi_pci_bridge_driver = { + .name ="axi-pci-bridge" , + .id_table = axi_pci_bridge_tbl, +}; + +int __init axi_pci_bridge_init (void ) +{ +return axi_host_pci_register (&axi_pci_bridge_driver); +} + +void __exit axi_pci_bridge_exit(void) +{ +axi_host_pci_unregister (&axi_pci_bridge_driver); +}
drivers/axi/axi_private.h new file +45 -0
45 lines not on this page · raw message
drivers/axi/core.c new file +52 -0
52 lines not on this page · raw message
drivers/axi/driver_chipcommon.c new file +87 -0
87 lines not on this page · raw message
drivers/axi/driver_chipcommon_pmu.c new file +134 -0
134 lines not on this page · raw message
drivers/axi/driver_pci.c new file +167 -0
167 lines not on this page · raw message
drivers/axi/host_pci.c new file +177 -0
177 lines not on this page · raw message
drivers/axi/main.c new file +256 -0
256 lines not on this page · raw message
drivers/axi/scan.c new file +393 -0
393 lines not on this page · raw message
drivers/axi/scan.h new file +56 -0
56 lines not on this page · raw message
include/linux/axi/axi.h new file +221 -0
221 lines not on this page · raw message
include/linux/axi/axi_driver_chipcommon.h new file +308 -0
308 lines not on this page · raw message
include/linux/axi/axi_driver_pci.h new file +89 -0
89 lines not on this page · raw message
include/linux/axi/axi_regs.h new file +34 -0
@@ -0,0 +1,34 @@ +#ifndef LINUX_AXI_REGS_H_ +#define LINUX_AXI_REGS_H_ + +/* Agent registers (common for every core) */ +#define AXI_IOCTL 0x0408 +#define AXI_IOCTL_CORE_BITS 0x3FFC +#define AXI_IOCTL_CLK 0x0001 +#define AXI_IOCTL_FGC 0x0002 +#define AXI_IOCTL_PME_EN 0x4000 +#define AXI_IOCTL_BIST_EN 0x8000 +#define AXI_RESET_CTL 0x0800 +#define AXI_RESET_CTL_RESET 0x0001 + +/* AXI PCI config space registers. */ +#define AXI_PCI_PMCSR 0x44 +#define AXI_PCI_PE 0x100 +#define AXI_PCI_BAR0_WIN 0x80/* Backplane address space 0 */ +#define AXI_PCI_BAR1_WIN 0x84/* Backplane address space 1 */ +#define AXI_PCI_SPROMCTL 0x88/* SPROM control */ +#define AXI_PCI_SPROMCTL_WE 0x10/* SPROM write enable */ +#define AXI_PCI_BAR1_CONTROL 0x8c/* Address space 1 burst control */ +#define AXI_PCI_IRQS 0x90/* PCI interrupts */ +#define AXI_PCI_IRQMASK 0x94/* PCI IRQ control and mask (pcirev >= 6 only) */ +#define AXI_PCI_BACKPLANE_IRQS 0x98/* Backplane Interrupts */ +#define AXI_PCI_BAR0_WIN2 0xAC +#define AXI_PCI_GPIO_IN 0xB0/* GPIO Input (pcirev >= 3 only) */ +#define AXI_PCI_GPIO_OUT 0xB4/* GPIO Output (pcirev >= 3 only) */ +#define AXI_PCI_GPIO_OUT_ENABLE 0xB8/* GPIO Output Enable/Disable (pcirev >= 3 only) */ +#define AXI_PCI_GPIO_SCS 0x10/* PCI config space bit 4 for 4306c0 slow clock source */ +#define AXI_PCI_GPIO_HWRAD 0x20/* PCI config space GPIO 13 for hw radio disable */ +#define AXI_PCI_GPIO_XTAL 0x40/* PCI config space GPIO 14 for Xtal powerup */ +#define AXI_PCI_GPIO_PLL 0x80/* PCI config space GPIO 15 for PLL powerdown */ + +#endif /* LINUX_AXI_REGS_H_ */
include/linux/mod_devicetable.h +17 -0
@@ -382,6 +382,23 @@ struct ssb_device_id {#define SSB_ANY_ID 0xFFFF#define SSB_ANY_REV 0xFF +/* AMBA AXI core, see drivers/axi/ */ +struct axi_device_id { +__u16 manuf; +__u16 id; +__u8 rev; +__u8 class; +}; +#define AXI_CORE (_manuf, _id, _rev, _class) \ + { .manuf = _manuf, .id = _id, .rev = _rev, .class = _class, } +#define AXI_CORETABLE_END \ + { 0, }, + +#define AXI_ANY_MANUF 0xFFFF +#define AXI_ANY_ID 0xFFFF +#define AXI_ANY_REV 0xFF +#define AXI_ANY_CLASS 0xFF +struct virtio_device_id {__u32 device;__u32 vendor;
scripts/mod/file2alias.c +21 -0
@@ -702,6 +702,23 @@ static int do_ssb_entry(const char *filename,return 1 ; } +/* Looks like: axi:mNidNrevNclN. */ +static int do_axi_entry (const char *filename, +struct axi_device_id *id,char *alias) +{ + id->manuf =TO_NATIVE (id->manuf); + id->id =TO_NATIVE (id->id); + id->rev =TO_NATIVE (id->rev); + +strcpy (alias,"axi:" ); +ADD (alias,"m" , id->manuf !=AXI_ANY_MANUF , id->manuf); +ADD (alias,"id" , id->id !=AXI_ANY_ID , id->id); +ADD (alias,"rev" , id->rev !=AXI_ANY_REV , id->rev); +ADD (alias,"cl" , id->class !=AXI_ANY_CLASS , id->class); +add_wildcard (alias); +return 1 ; +} +/* Looks like: virtio:dNvN */ static int do_virtio_entry (const char *filename,struct virtio_device_id *id,char *alias)
@@ -968,6 +985,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,do_table (symval, sym->st_size,sizeof (struct ssb_device_id ),"ssb" , do_ssb_entry, mod); + else if (sym_is(symname, "__mod_axi_device_table")) + do_table(symval, sym->st_size, + sizeof(struct axi_device_id), "axi", + do_axi_entry, mod); else if (sym_is(symname, "__mod_virtio_device_table")) do_table(symval, sym->st_size, sizeof(struct virtio_device_id), "virtio",
Signature · 1 line
1.7.3.4
drivers/axi/main.c line 74
Quoted 4 lines · Rafa? Mi?ecki
drivers/axi/main.c new file +4
-0+static void axi_release_core_dev (struct device *dev) +{ +/* Silent lack-of-release warning */ +}
Ok, WTF!!!!
As per the documentation in the kernel I now get to publically mock you for trying to be smarter than the kernel. Why did you think that if you just magically gave an empty function to the kernel it would solve the problem that THE KERNEL WAS TRYING TO TELL YOU TO FIX IN THE FIRST PLACE?
{sigh}
It's as if no one reads the documentation, or even pays attention to the message that the kernel spits out and they think they know better.
Totally and completely unacceptable.
Fix this now.
greg k-h
Quoted 41 lines · Rafa? Mi?ecki
Cc Michael B?sch <[email protected]>Cc Larry Finger <[email protected]>Cc George Kashperko <[email protected]>Cc Arend van Spriel <[email protected]>Cc linux-arm-kernel at lists.infradead.org <[email protected]>Cc Russell King <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Andy Botting <[email protected]>Cc linuxdriverproject <[email protected]>Cc linux-kernel at vger.kernel.org <[email protected]>Signed-off-by Rafa? Mi?ecki <[email protected]>---
V2: Rename to axi
UseDEFINE_PCI_DEVICE_TABLEin bridge
Make use ofpr_fmtand pr_*
Store core class
Rename bridge to not b43 specific
Replace magic0x1000withBCMAI_CORE_SIZERemove some old "ssb" names and defines
MoveBCMAI_ADDR_BASEdef
Add drvdata field
V3: Fix reloading (kfree issue)
Add 14e4:4331
Fix non-initialized struct issue
Drop useless inline functions wrappers for pci core drv Proper pr_* usage
Helps inKconfig--- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/axi/Kconfig | 33 +++ drivers/axi/Makefile | 7 + drivers/axi/TODO | 3 + drivers/axi/axi_pci_bridge.c | 34 +++ drivers/axi/axi_private.h | 45 ++++ drivers/axi/core.c | 52 ++++ drivers/axi/driver_chipcommon.c | 87 +++++++ drivers/axi/driver_chipcommon_pmu.c | 134 ++++++++++ drivers/axi/driver_pci.c | 167 ++++++++++++ drivers/axi/host_pci.c | 177 +++++++++++++ drivers/axi/main.c | 256 +++++++++++++++++++
Quoted 8 lines
drivers/axi/scan.c | 393 +++++++++++++++++++++++++++++ drivers/axi/scan.h | 56 ++++ include/linux/axi/axi.h | 221 ++++++++++++++++ include/linux/axi/axi_driver_chipcommon.h | 308 ++++++++++++++++++++++ include/linux/axi/axi_driver_pci.h | 89 +++++++ include/linux/axi/axi_regs.h | 34 +++ include/linux/mod_devicetable.h | 17 ++ scripts/mod/file2alias.c | 21 ++
Where is the documentation files for the new sysfs files you just created?
thanks,
greg k-h
2011/4/11 Greg KH <[email protected]>:
Quoted 7 lines · Rafa? Mi?ecki
drivers/axi/main.c line 74
Quoted 4 lines
drivers/axi/main.c new file +4
-0+static void axi_release_core_dev (struct device *dev) +{ + ? ? /* Silent lack-of-release warning */ +}Ok, WTF!!!!
Thank you for your kindly words. It's much more enjoyable to work on kernel that way. I definitely made that on purpose.
Signature · 1 line
Rafa?
Quoted 11 lines · Rafa? Mi?ecki
2011/4/11 Greg KH <[email protected]>:
Quoted 7 lines · Rafa? Mi?ecki
drivers/axi/main.c line 74
Quoted 4 lines
drivers/axi/main.c new file +4
-0+static void axi_release_core_dev (struct device *dev) +{ + ? ? /* Silent lack-of-release warning */ +}Ok, WTF!!!!
Thank you for your kindly words. It's much more enjoyable to work on kernel that way. I definitely made that on purpose.
I can't tell if you are kidding or not.
Please read the documentation for how to do this properly. I find it really hard to believe that you wrote that comment instead of putting in the 2 lines of code required for this function.
Especially as-it-is, your code does not work properly and leaks memory badly. Why would you do that on purpose?
thanks,
greg k-h
2011/4/11 Greg KH <[email protected]>:
Quoted 10 lines · Rafa? Mi?ecki
Quoted 9 lines
2011/4/11 Greg KH <[email protected]>:
Quoted 7 lines · Rafa? Mi?ecki
drivers/axi/main.c line 74
Quoted 4 lines
drivers/axi/main.c new file +4
-0+static void axi_release_core_dev (struct device *dev) +{ + ? ? /* Silent lack-of-release warning */ +}Ok, WTF!!!!
Quoted 4 lines
Quoted 2 lines
Thank you for your kindly words. It's much more enjoyable to work on kernel that way. I definitely made that on purpose.
I can't tell if you are kidding or not.
That was 100% irony. I swear I don't enjoy publishing bad code and getting such a comment.
Quoted 6 lines
Please read the documentation for how to do this properly. ?I find it really hard to believe that you wrote that comment instead of putting in the 2 lines of code required for this function.
Especially as-it-is, your code does not work properly and leaks memory badly. ?Why would you do that on purpose?
I tried to read some documentation about this.
1) driver-mode/device.txt says only that:
Quoted 3 lines
Callback to free the device after all references have gone away. This should be set by the allocator of the device (i.e. the bus driver that discovered the device).
I *really* do not know how my driver should "free" core on AXI bus.
2) LDD3 says:
Quoted 3 lines
The method is called when the last reference to the device is removed; it is called from the embedded kobject?s release method. All device structures registered with the core must have a release method, or the kernel prints out scary complaints.
Well, I do not register any structs for AXI core.
3) Example code from LDD3:
static void ldd_bus_release(struct device *dev)
{printk(KERN_DEBUG "lddbus release\n");
}
Yeah, that's what I did...
4) SSB in it's ssb_release_dev just calls kfree on struct that was allocated when registering drivers. *I do not* allocate such a struct, so I believe I do exactly the same memory leak as SSB does.
Can you spend 2 more minues in addition to commenting my ideas and help me with writing that 2 lines I missed? Where do I leak memory in my driver? Which struct should I kfree?
Signature · 1 line
Rafa?
Quoted 11 lines · Rafa? Mi?ecki
2011/4/11 Greg KH <[email protected]>:
Quoted 10 lines · Rafa? Mi?ecki
Quoted 9 lines
2011/4/11 Greg KH <[email protected]>:
Quoted 7 lines · Rafa? Mi?ecki
drivers/axi/main.c line 74
Quoted 4 lines
drivers/axi/main.c new file +4
-0+static void axi_release_core_dev (struct device *dev) +{ + ? ? /* Silent lack-of-release warning */ +}Ok, WTF!!!!
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Thank you for your kindly words. It's much more enjoyable to work on kernel that way. I definitely made that on purpose.
I can't tell if you are kidding or not.
That was 100% irony. I swear I don't enjoy publishing bad code and getting such a comment.
Ok, you forgot the ':)' then...
Quoted 7 lines
Quoted 6 lines
Please read the documentation for how to do this properly. ?I find it really hard to believe that you wrote that comment instead of putting in the 2 lines of code required for this function.
Especially as-it-is, your code does not work properly and leaks memory badly. ?Why would you do that on purpose?
Quoted 7 lines
I tried to read some documentation about this.
1)
driver-mode/device.txtsays only that:Quoted 3 lines
Callback to free the device after all references have gone away. This should be set by the allocator of the device (i.e. the bus driver that discovered the device).
I *really* do not know how my driver should "free" core on AXI bus.
The structure that you have created, added to the bus, is now ready to have its memory freed. So free it.
This usually means something like:
struct my_obj = to_my_obj(dev); kfree(my_obj);
in the release function.
Quoted 5 lines
2) LDD3 says:
Quoted 3 lines
The method is called when the last reference to the device is removed; it is called from the embedded kobject?s release method. All device structures registered with the core must have a release method, or the kernel prints out scary complaints.
Well, I do not register any structs for AXI core.
Yes you did, otherwise you would have never seen that callback warning you that you needed a release function.
Quoted 6 lines
3) Example code from LDD3:
static voidldd_bus_release(struct device *dev)
{printk(KERN_DEBUG "lddbus release\n");
}
Yeah, that's what I did...
Wow that's old, sorry. See the kobject documentation for much more detail about what you need here.
Quoted 3 lines
4) SSB in it's
ssb_release_devjust calls kfree on struct that was allocated when registering drivers. *I do not* allocate such a struct, so I believe I do exactly the same memory leak as SSB does.
Well someone allocated it, right? Who did it? If it wasn't you, where did that structure come from and why are you registering it on your bus?
Quoted 3 lines
Can you spend 2 more minues in addition to commenting my ideas and help me with writing that 2 lines I missed? Where do I leak memory in my driver? Which struct should I kfree?
The structure that you wrap around 'struct device' for your bus.
hope this helps,
greg k-h
2011/4/11 Greg KH <[email protected]>:
Quoted 17 lines · Rafa? Mi?ecki
Quoted 8 lines
2011/4/11 Greg KH <[email protected]>:
Quoted 6 lines
Please read the documentation for how to do this properly. ?I find it really hard to believe that you wrote that comment instead of putting in the 2 lines of code required for this function.
Especially as-it-is, your code does not work properly and leaks memory badly. ?Why would you do that on purpose?
Quoted 7 lines
I tried to read some documentation about this.
1)
driver-mode/device.txtsays only that:Quoted 3 lines
Callback to free the device after all references have gone away. This should be set by the allocator of the device (i.e. the bus driver that discovered the device).
I *really* do not know how my driver should "free" core on AXI bus.
Quoted 7 lines
The structure that you have created, added to the bus, is now ready to have its memory freed. ?So free it.
This usually means something like:
? ? ? ?structmy_obj=to_my_obj(dev);
? ? ? ?kfree(my_obj);
in the release function.
I register core->dev to the bus (I set core->dev.bus and core->dev.parent, is that what you mean?). This core->dev is "struct dev" embedded in "struct axi_device". By embedded I mean it is *not* a pointer, I do not alloc it, it's part of the "struct axi_device".
Quoted 8 lines
Quoted 5 lines
2) LDD3 says:
Quoted 3 lines
The method is called when the last reference to the device is removed; it is called from the embedded kobject?s release method. All device structures registered with the core must have a release method, or the kernel prints out scary complaints.
Well, I do not register any structs for AXI core.
Yes you did, otherwise you would have never seen that callback warning you that you needed a release function.
I was thinking about alloc, sorry, ignore this one.
Quoted 4 lines
Quoted 3 lines
4) SSB in it's
ssb_release_devjust calls kfree on struct that was allocated when registering drivers. *I do not* allocate such a struct, so I believe I do exactly the same memory leak as SSB does.
Quoted 8 lines
Well someone allocated it, right? ?Who did it? ?If it wasn't you, where did that structure come from and why are you registering it on your bus?
Quoted 3 lines
Can you spend 2 more minues in addition to commenting my ideas and help me with writing that 2 lines I missed? Where do I leak memory in my driver? Which struct should I kfree?
The structure that you wrap around 'struct device' for your bus.
As explained above, this I do not dynamically alloc this 'struct device'. So is there really any memory leak?
Signature · 1 line
Rafa?
Quoted 26 lines · Rafa? Mi?ecki
2011/4/11 Greg KH <[email protected]>:
Quoted 17 lines · Rafa? Mi?ecki
Quoted 8 lines
2011/4/11 Greg KH <[email protected]>:
Quoted 6 lines
Please read the documentation for how to do this properly. ?I find it really hard to believe that you wrote that comment instead of putting in the 2 lines of code required for this function.
Especially as-it-is, your code does not work properly and leaks memory badly. ?Why would you do that on purpose?
Quoted 7 lines
I tried to read some documentation about this.
1)
driver-mode/device.txtsays only that:Quoted 3 lines
Callback to free the device after all references have gone away. This should be set by the allocator of the device (i.e. the bus driver that discovered the device).
I *really* do not know how my driver should "free" core on AXI bus.
Quoted 7 lines
The structure that you have created, added to the bus, is now ready to have its memory freed. ?So free it.
This usually means something like:
? ? ? ?structmy_obj=to_my_obj(dev);
? ? ? ?kfree(my_obj);
in the release function.
Quoted 4 lines
I register
core->devto the bus (I setcore->dev.busandcore->dev.parent, is that what you mean?). Thiscore->devis "struct dev" embedded in "structaxi_device". By embedded I mean it is *not* a pointer, I do not alloc it, it's part of the "structaxi_device".
That is exactly as it should be.
Then in your release function, free the struct axi_device. It's that simple. To try to free it before then would be wrong and cause problems.
Quoted 19 lines
Quoted 8 lines
Quoted 5 lines
2) LDD3 says:
Quoted 3 lines
The method is called when the last reference to the device is removed; it is called from the embedded kobject?s release method. All device structures registered with the core must have a release method, or the kernel prints out scary complaints.
Well, I do not register any structs for AXI core.
Yes you did, otherwise you would have never seen that callback warning you that you needed a release function.
I was thinking about alloc, sorry, ignore this one.
Quoted 7 lines
Quoted 3 lines
4) SSB in it's
ssb_release_devjust calls kfree on struct that was allocated when registering drivers. *I do not* allocate such a struct, so I believe I do exactly the same memory leak as SSB does.Well someone allocated it, right? ?Who did it? ?If it wasn't you, where did that structure come from and why are you registering it on your bus?
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Can you spend 2 more minues in addition to commenting my ideas and help me with writing that 2 lines I missed? Where do I leak memory in my driver? Which struct should I kfree?
The structure that you wrap around 'struct device' for your bus.
As explained above, this I do not dynamically alloc this 'struct device'. So is there really any memory leak?
Yes, no one ever freed your struct axi_device that you created.
thanks,
greg k-h
2011/4/12 Greg KH <[email protected]>:
Quoted 32 lines · Rafa? Mi?ecki
Quoted 26 lines
2011/4/11 Greg KH <[email protected]>:
Quoted 17 lines · Rafa? Mi?ecki
Quoted 8 lines
2011/4/11 Greg KH <[email protected]>:
Quoted 6 lines
Please read the documentation for how to do this properly. ?I find it really hard to believe that you wrote that comment instead of putting in the 2 lines of code required for this function.
Especially as-it-is, your code does not work properly and leaks memory badly. ?Why would you do that on purpose?
Quoted 7 lines
I tried to read some documentation about this.
1)
driver-mode/device.txtsays only that:Quoted 3 lines
Callback to free the device after all references have gone away. This should be set by the allocator of the device (i.e. the bus driver that discovered the device).
I *really* do not know how my driver should "free" core on AXI bus.
Quoted 7 lines
The structure that you have created, added to the bus, is now ready to have its memory freed. ?So free it.
This usually means something like:
? ? ? ?structmy_obj=to_my_obj(dev);
? ? ? ?kfree(my_obj);
in the release function.Quoted 4 lines
I register
core->devto the bus (I setcore->dev.busandcore->dev.parent, is that what you mean?). Thiscore->devis "struct dev" embedded in "structaxi_device". By embedded I mean it is *not* a pointer, I do not alloc it, it's part of the "structaxi_device".
Quoted 5 lines
That is exactly as it should be.
Then in your release function, free the struct
axi_device. ?It's that simple. ?To try to free it before then would be wrong and cause problems.
This is because it is defined as:
struct axi_device cores[AXI_MAX_NR_CORES];
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
4) SSB in it's
ssb_release_devjust calls kfree on struct that was allocated when registering drivers. *I do not* allocate such a struct, so I believe I do exactly the same memory leak as SSB does.Well someone allocated it, right? ?Who did it? ?If it wasn't you, where did that structure come from and why are you registering it on your bus?
Quoted 3 lines
Can you spend 2 more minues in addition to commenting my ideas and help me with writing that 2 lines I missed? Where do I leak memory in my driver? Which struct should I kfree?
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
The structure that you wrap around 'struct device' for your bus.
As explained above, this I do not dynamically alloc this 'struct device'. So is there really any memory leak?
Yes, no one ever freed your struct
axi_devicethat you created.
I agree that defining "cores" as array with maxium possible size instead of linked list eats more memory than needed, but at least it does not leak anything.
Signature · 1 line
Rafa?
Quoted 33 lines · Rafa? Mi?ecki
2011/4/12 Greg KH <[email protected]>:
Quoted 32 lines · Rafa? Mi?ecki
Quoted 30 lines
2011/4/11 Greg KH <[email protected]>:
Quoted 17 lines · Rafa? Mi?ecki
Quoted 8 lines
2011/4/11 Greg KH <[email protected]>:
Quoted 6 lines
Please read the documentation for how to do this properly. ?I find it really hard to believe that you wrote that comment instead of putting in the 2 lines of code required for this function.
Especially as-it-is, your code does not work properly and leaks memory badly. ?Why would you do that on purpose?
Quoted 7 lines
I tried to read some documentation about this.
1)
driver-mode/device.txtsays only that:Quoted 3 lines
Callback to free the device after all references have gone away. This should be set by the allocator of the device (i.e. the bus driver that discovered the device).
I *really* do not know how my driver should "free" core on AXI bus.
Quoted 7 lines
The structure that you have created, added to the bus, is now ready to have its memory freed. ?So free it.
This usually means something like:
? ? ? ?structmy_obj=to_my_obj(dev);
? ? ? ?kfree(my_obj);
in the release function.I register
core->devto the bus (I setcore->dev.busandcore->dev.parent, is that what you mean?). Thiscore->devis "struct dev" embedded in "structaxi_device". By embedded I mean it is *not* a pointer, I do not alloc it, it's part of the "structaxi_device".
Quoted 8 lines
Quoted 5 lines
That is exactly as it should be.
Then in your release function, free the struct
axi_device. ?It's that simple. ?To try to free it before then would be wrong and cause problems.This is because it is defined as:
structaxi_devicecores[AXI_MAX_NR_CORES];
No way, seriously?
You can't do that, no static struct devices please. Make these dynamic and everything will be fine. The -mm tree used to have a huge warning if you ever tried to register a statically allocated struct, but that didn't really work out, but would have saved you a lot of time here, sorry.
So dynamically allocate the structures and you will be fine.
thanks,
greg k-h
Quoted 1 line · Rafa? Mi?ecki
Proper pr_* usage
Just trivia...
Quoted 8 lines
drivers/axi/axi_private.h new file +2
-0@@ -0,0 +1,45 @@ +#ifndef LINUX_AXI_PRIVATE_H_ +#define LINUX_AXI_PRIVATE_H_
drivers/axi/axi_private.h line 12
Quoted 10 lines
drivers/axi/axi_private.h new file +10
-0+ +#include <linux/axi/axi.h> +#include <linux/device.h> +#include <linux/list.h> +#include <linux/types.h> +#include <linux/spinlock.h> +#include <linux/pci.h> +#include <linux/mod_devicetable.h> +#include <linux/dma-mapping.h> +#include <linux/types.h>
Duplicate include of linux/types.h
drivers/axi/axi_private.h line 16
Quoted 4 lines
drivers/axi/axi_private.h new file +4
-0+ +#ifndef pr_fmt +#define pr_fmt (fmt) "axi: " fmt +#endif
This needs to be before any include that includes kernel.h and I believe
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
is the same output and more normally used style.
Right now, you've got no prefix for any format string. Try '$ strings built-in.o | grep "^<.>"' and see.
drivers/axi/axi_private.h line 22
Quoted 6 lines
drivers/axi/axi_private.h new file +6
-0+void axi_pmu_workarounds (struct axi_drv_cc *cc) +{ +struct axi_bus *bus = cc->core->bus; + +switch (bus->chipinfo.id) { +case 0x4313 :
Probably better to use defines.
drivers/axi/axi_private.h line 26
Quoted 4 lines
drivers/axi/axi_private.h new file +4
-0+axi_chipco_chipctl_maskset (cc,0 , ~0 ,0x7 ); +break ; +case 0x4331 : +axi_err ("Enabling Ext PA lines not implemented\n" );
You should still remove axi_err/info/debug and just use pr_<level>.
drivers/axi/axi_private.h line 31
Quoted 5 lines
drivers/axi/axi_private.h new file +5
-0+break ; +case 43224 : +if (bus->chipinfo.rev ==0 ) { +axi_err ("Workarounds for 43224 rev 0 not fully " +"implemented\n" );
I suggest you don't bother splitting and wrapping format strings > 80 chars. Splitting makes grep a bit harder.
pr_err("Workarounds for 43224 rev 0 not fully implemented\n");Some hex and some decimal cases?
Maybe some comments for that?
2011/4/12 Greg KH <[email protected]>:
Quoted 45 lines · Rafa? Mi?ecki
Quoted 33 lines
2011/4/12 Greg KH <[email protected]>:
Quoted 32 lines · Rafa? Mi?ecki
Quoted 30 lines
2011/4/11 Greg KH <[email protected]>:
Quoted 17 lines · Rafa? Mi?ecki
Quoted 8 lines
2011/4/11 Greg KH <[email protected]>:
Quoted 6 lines
Please read the documentation for how to do this properly. ?I find it really hard to believe that you wrote that comment instead of putting in the 2 lines of code required for this function.
Especially as-it-is, your code does not work properly and leaks memory badly. ?Why would you do that on purpose?
Quoted 7 lines
I tried to read some documentation about this.
1)
driver-mode/device.txtsays only that:Quoted 3 lines
Callback to free the device after all references have gone away. This should be set by the allocator of the device (i.e. the bus driver that discovered the device).
I *really* do not know how my driver should "free" core on AXI bus.
Quoted 7 lines
The structure that you have created, added to the bus, is now ready to have its memory freed. ?So free it.
This usually means something like:
? ? ? ?structmy_obj=to_my_obj(dev);
? ? ? ?kfree(my_obj);
in the release function.I register
core->devto the bus (I setcore->dev.busandcore->dev.parent, is that what you mean?). Thiscore->devis "struct dev" embedded in "structaxi_device". By embedded I mean it is *not* a pointer, I do not alloc it, it's part of the "structaxi_device".Quoted 8 lines
Quoted 5 lines
That is exactly as it should be.
Then in your release function, free the struct
axi_device. ?It's that simple. ?To try to free it before then would be wrong and cause problems.This is because it is defined as:
structaxi_devicecores[AXI_MAX_NR_CORES];No way, seriously?
Quoted 7 lines
You can't do that, no static struct devices please. ?Make these dynamic and everything will be fine. ?The -mm tree used to have a huge warning if you ever tried to register a statically allocated struct, but that didn't really work out, but would have saved you a lot of time here, sorry.
So dynamically allocate the structures and you will be fine.
Well, I saw that along kernel, I had no idea there is anything wrong about this. It seems more ppl do not know about this:
struct radeon_ib ibs[RADEON_IB_POOL_SIZE];
struct radeon_pm_clock_info clock_info[8];
struct radeon_pm_profile profiles[PM_PROFILE_MAX];
struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES]; struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
struct b43_key key[B43_NR_GROUP_KEYS * 2 + B43_NR_PAIRWISE_KEYS];
struct ssb_device devices[SSB_MAX_NR_CORES];
I guess I could fine more examples by simple grepping .h files.
Is there some guide around with things like this we should avoid? checkpatch does no catch this, so maybe just some manual? Could you point me to it?
Signature · 1 line
Rafa?
2011/4/12 Joe Perches <[email protected]>:
Quoted 5 lines · Rafa? Mi?ecki
Quoted 2 lines
? Proper pr_* usage
Just trivia...
The patch you were reviewing does not have pr_* stuff included, sorry. I published V3 by mistake missing some changes. Patch V3.1 alreay fixes that.
Quoted 12 lines
Quoted 12 lines
drivers/axi/axi_private.h new file +6
-0@@ -0,0 +1,45 @@ +#ifndef LINUX_AXI_PRIVATE_H_ +#define LINUX_AXI_PRIVATE_H_ + +#include <linux/axi/axi.h> +#include <linux/device.h> +#include <linux/list.h>
Quoted 8 lines
drivers/axi/axi_private.h line 12
Quoted 6 lines
drivers/axi/axi_private.h new file +6
-0+#include <linux/types.h> +#include <linux/spinlock.h> +#include <linux/pci.h> +#include <linux/mod_devicetable.h> +#include <linux/dma-mapping.h> +#include <linux/types.h> Duplicate include of
linux/types.h
V3.1
Quoted 10 lines
drivers/axi/axi_private.h line 16
Quoted 4 lines
drivers/axi/axi_private.h new file +4
-0+ +#ifndef pr_fmt +#define pr_fmt (fmt) ? ? ? ? ?"axi: " fmt +#endif This needs to be before any include that includes
kernel.hand I believe
#definepr_fmt(fmt)KBUILD_MODNAME": " fmt
is the same output and more normally used style.
Quoted 2 lines
Right now, you've got no prefix for any format string. Try '$ strings built-in.o | grep "^<.>"' and see.
V3.1
Quoted 8 lines
drivers/axi/axi_private.h line 22
Quoted 6 lines
drivers/axi/axi_private.h new file +6
-0+void axi_pmu_workarounds (struct axi_drv_cc *cc) +{ + ? ? struct axi_bus *bus = cc->core->bus; + + ? ? switch (bus->chipinfo.id) { + ? ? case 0x4313:Probably better to use defines.
That magic hex values always match common name of chipsets, so it's looks pretty clean/obvious... Not sure if it's worth it?
Quoted 7 lines
drivers/axi/axi_private.h line 26
Quoted 4 lines
drivers/axi/axi_private.h new file +4
-0+ ? ? ? ? ? ? axi_chipco_chipctl_maskset(cc, 0, ~0, 0x7); + ? ? ? ? ? ? break; + ? ? case 0x4331: + ? ? ? ? ? ? axi_err("Enabling Ext PA lines not implemented\n");You should still remove axi_err/info/debug and just use pr_<level>.
V3.1
Quoted 6 lines
drivers/axi/axi_private.h line 31
Quoted 5 lines
drivers/axi/axi_private.h new file +5
-0+ ? ? ? ? ? ? break; + ? ? case 43224: + ? ? ? ? ? ? if (bus->chipinfo.rev == 0) { + ? ? ? ? ? ? ? ? ? ? axi_err("Workarounds for 43224 rev 0 not fully " + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "implemented\n");
Quoted 8 lines
I suggest you don't bother splitting and wrapping format strings > 80 chars. ?Splitting makes grep a bit harder.
? ? ? ? ? ? ? ? ? ? ? ?pr_err("Workarounds for 43224 rev 0 not fully implemented\n");
Some hex and some decimal cases?
Maybe some comments for that?
Well, such a trick from Broadcom. I believe wanted to keep 43* names for the chipsets, they invented sth like 43224 but they had only 0xFFFF. So the used 0xA8D8==43224.
Signature · 1 line
Rafa?
2011/4/12 Rafa? Mi?ecki <[email protected]>:
Quoted 28 lines
2011/4/12 Greg KH <[email protected]>:
Quoted 11 lines · Rafa? Mi?ecki
Quoted 7 lines
2011/4/12 Greg KH <[email protected]>:
Quoted 3 lines
Then in your release function, free the struct
axi_device. ?It's that simple. ?To try to free it before then would be wrong and cause problems.This is because it is defined as:
structaxi_devicecores[AXI_MAX_NR_CORES];No way, seriously?
Quoted 7 lines
You can't do that, no static struct devices please. ?Make these dynamic and everything will be fine. ?The -mm tree used to have a huge warning if you ever tried to register a statically allocated struct, but that didn't really work out, but would have saved you a lot of time here, sorry.
So dynamically allocate the structures and you will be fine.
Well, I saw that along kernel, I had no idea there is anything wrong about this. It seems more ppl do not know about this:
structradeon_ib? ? ? ?ibs[RADEON_IB_POOL_SIZE];
structradeon_pm_clock_infoclock_info[8];
structradeon_pm_profileprofiles[PM_PROFILE_MAX];
structradeon_surface_regsurface_regs[RADEON_GEM_MAX_SURFACES]; structradeon_i2c_chan*i2c_bus[RADEON_MAX_I2C_BUS];
Quoted 8 lines
struct
b43_keykey[B43_NR_GROUP_KEYS * 2 +B43_NR_PAIRWISE_KEYS];struct
ssb_devicedevices[SSB_MAX_NR_CORES];
I guess I could fine more examples by simple grepping .h files.Is there some guide around with things like this we should avoid? checkpatch does no catch this, so maybe just some manual? Could you point me to it?
Greg, my:
struct ssb_device devices[SSB_MAX_NR_CORES];
is part of "struct axi_bus", which we allocate dynamically anyway:
struct axi_bus *bus;
bus = kzalloc(sizeof(*bus), GFP_KERNEL);
if (!bus)
goto out;
So do we really need to dynamically alloc main structure and separately every of it's array of structs? Does it really make sense? Please point me to some place where I can read more about this. Some tips about coding style for such things, cases.
Signature · 1 line
Rafa?
Quoted 6 lines · Rafa? Mi?ecki
Quoted 6 lines
You can't do that, no static struct devices please. ?Make these dynamic and everything will be fine. ?The -mm tree used to have a huge warning if you ever tried to register a statically allocated struct, but that didn't really work out, but would have saved you a lot of time here, sorry.
Quoted 8 lines
Quoted 1 line
So dynamically allocate the structures and you will be fine.
Well, I saw that along kernel, I had no idea there is anything wrong about this. It seems more ppl do not know about this:
structradeon_ibibs[RADEON_IB_POOL_SIZE];
structradeon_pm_clock_infoclock_info[8];
structradeon_pm_profileprofiles[PM_PROFILE_MAX];
structradeon_surface_regsurface_regs[RADEON_GEM_MAX_SURFACES];
Are you sure these are all containing a 'struct device'?
Quoted 1 line
struct
radeon_i2c_chan*i2c_bus[RADEON_MAX_I2C_BUS];
This is an array of pointers, that's fine.
Quoted 1 line
struct
b43_keykey[B43_NR_GROUP_KEYS * 2 +B43_NR_PAIRWISE_KEYS];
This contains a 'struct device'?
Quoted 2 lines
struct
ssb_devicedevices[SSB_MAX_NR_CORES];
I guess I could fine more examples by simple grepping .h files.
Then all of the above should be fixed.
Quoted 1 line
Is there some guide around with things like this we should avoid?
Yes, do not statically allocate a 'struct device'.
Quoted 2 lines
checkpatch does no catch this, so maybe just some manual? Could you point me to it?
It's a structure that has dynamic lifetime rules, you can't statically allocate it safely. It's that simple.
Please fix this.
thanks,
greg k-h
Quoted 42 lines · Rafa? Mi?ecki
2011/4/12 Rafa? Mi?ecki <[email protected]>:
Quoted 28 lines
2011/4/12 Greg KH <[email protected]>:
Quoted 11 lines · Rafa? Mi?ecki
Quoted 7 lines
2011/4/12 Greg KH <[email protected]>:
Quoted 3 lines
Then in your release function, free the struct
axi_device. ?It's that simple. ?To try to free it before then would be wrong and cause problems.This is because it is defined as:
structaxi_devicecores[AXI_MAX_NR_CORES];No way, seriously?
Quoted 7 lines
You can't do that, no static struct devices please. ?Make these dynamic and everything will be fine. ?The -mm tree used to have a huge warning if you ever tried to register a statically allocated struct, but that didn't really work out, but would have saved you a lot of time here, sorry.
So dynamically allocate the structures and you will be fine.
Well, I saw that along kernel, I had no idea there is anything wrong about this. It seems more ppl do not know about this:
structradeon_ib? ? ? ?ibs[RADEON_IB_POOL_SIZE];
structradeon_pm_clock_infoclock_info[8];
structradeon_pm_profileprofiles[PM_PROFILE_MAX];
structradeon_surface_regsurface_regs[RADEON_GEM_MAX_SURFACES]; structradeon_i2c_chan*i2c_bus[RADEON_MAX_I2C_BUS];Quoted 8 lines
struct
b43_keykey[B43_NR_GROUP_KEYS * 2 +B43_NR_PAIRWISE_KEYS];struct
ssb_devicedevices[SSB_MAX_NR_CORES];
I guess I could fine more examples by simple grepping .h files.Is there some guide around with things like this we should avoid? checkpatch does no catch this, so maybe just some manual? Could you point me to it?
Greg, my:
structssb_devicedevices[SSB_MAX_NR_CORES];
is part of "structaxi_bus", which we allocate dynamically anyway:
Quoted 7 lines
struct
axi_bus*bus;
bus =kzalloc(sizeof(*bus), GFP_KERNEL);
if (!bus)goto out;So do we really need to dynamically alloc main structure and separately every of it's array of structs? Does it really make sense?
What? You allocate the bus and all of the devices all at once? That's insane.
Quoted 2 lines
Please point me to some place where I can read more about this. Some tips about coding style for such things, cases.
Any structure that is reference counted, can only be reference counted by one part of that object, AND it has to be unique from all other objects.
thanks,
greg k-h
2011/4/12 Greg KH <[email protected]>:
Quoted 9 lines · Rafa? Mi?ecki
Quoted 8 lines
Quoted 7 lines
You can't do that, no static struct devices please. ?Make these dynamic and everything will be fine. ?The -mm tree used to have a huge warning if you ever tried to register a statically allocated struct, but that didn't really work out, but would have saved you a lot of time here, sorry.
So dynamically allocate the structures and you will be fine.
Quoted 8 lines
Quoted 6 lines
Well, I saw that along kernel, I had no idea there is anything wrong about this. It seems more ppl do not know about this:
structradeon_ib? ? ?ibs[RADEON_IB_POOL_SIZE];
structradeon_pm_clock_infoclock_info[8];
structradeon_pm_profileprofiles[PM_PROFILE_MAX];
structradeon_surface_regsurface_regs[RADEON_GEM_MAX_SURFACES];Are you sure these are all containing a 'struct device'?
I didn't catch from you mail that you mean "struct device" only. I though it apply to all structs.
Quoted 5 lines
Quoted 2 lines
checkpatch does no catch this, so maybe just some manual? Could you point me to it?
It's a structure that has dynamic lifetime rules, you can't statically allocate it safely. ?It's that simple.
Ah, and this is a great explanation, for all the time I tough the problem is memory issue. Now it makes sense, thanks.
Signature · 1 line
Rafa?