Skip to contentSkip to conversation

new module for amba axi on-chip interconnect

PATCH In review Arend van Spriel 7 participants 19 messages Mar 29, 2011 – Apr 1, 2011

lore
Share & tools
lore
#0 lore raw

cover new module for amba axi on-chip interconnect

GUIDANCE NEEDED:
This patch puts the module at proposed location. Please provide your guidance if there is a better location within the linux tree for this module.

This module has been isolated from the brcm80211 driver currently located in staging and provided to other drivers for chipsets using the AMBA AXI on-chip interconnect with ARM Device Management Plugin (DMP) silicon IP, which provides system discovery (chip being the system) and basic core function (disable, reset, etc.).

The module has previously been posted on the linux-wireless list and comments by Randy Dunlap have been taken in. Also the SubmitChecklist has been followed.

Arend van Spriel (1):
drivers: brcmaxi: provide amba axi functionality in separate module

 drivers/Kconfig            |    2 +
 drivers/Makefile           |    1 +
 drivers/brcmaxi/Kconfig    |   23 ++
 drivers/brcmaxi/Makefile   |   25 ++
 drivers/brcmaxi/axi.c      |  786 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/brcmaxi/axi_priv.h |   51 +++
 drivers/brcmaxi/pci.c      |  118 +++++++
 include/brcmaxi/amba.h     |   87 +++++
 include/brcmaxi/axi.h      |  310 +++++++++++++++++
 include/brcmaxi/pci.h      |  112 +++++++
 10 files changed, 1515 insertions(+), 0 deletions(-)
 create mode 100644 drivers/brcmaxi/Kconfig
 create mode 100644 drivers/brcmaxi/Makefile
 create mode 100644 drivers/brcmaxi/axi.c
 create mode 100644 drivers/brcmaxi/axi_priv.h
 create mode 100644 drivers/brcmaxi/pci.c
 create mode 100644 include/brcmaxi/amba.h
 create mode 100644 include/brcmaxi/axi.h
 create mode 100644 include/brcmaxi/pci.h
#1 lore raw

PATCH 1/1 drivers: brcmaxi: provide amba axi functionality in separate module

The open-source community is looking for a library which will detect cores in a chip using axi backplane. This is an initial delivery of what it could look like. Tested it with the Broadcom open-source mac80211 wireless driver located in drivers/staging/brcm80211.

---
 drivers/Kconfig            |    2 +
 drivers/Makefile           |    1 +
 drivers/brcmaxi/Kconfig    |   23 ++
 drivers/brcmaxi/Makefile   |   25 ++
 drivers/brcmaxi/axi.c      |  786 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/brcmaxi/axi_priv.h |   51 +++
 drivers/brcmaxi/pci.c      |  118 +++++++
 include/brcmaxi/amba.h     |   87 +++++
 include/brcmaxi/axi.h      |  310 +++++++++++++++++
 include/brcmaxi/pci.h      |  112 +++++++
 10 files changed, 1515 insertions(+), 0 deletions(-)
 create mode 100644 drivers/brcmaxi/Kconfig
 create mode 100644 drivers/brcmaxi/Makefile
 create mode 100644 drivers/brcmaxi/axi.c
 create mode 100644 drivers/brcmaxi/axi_priv.h
 create mode 100644 drivers/brcmaxi/pci.c
 create mode 100644 include/brcmaxi/amba.h
 create mode 100644 include/brcmaxi/axi.h
 create mode 100644 include/brcmaxi/pci.h
drivers/Kconfig +2 -0
index 177c7d1..8617526 100644
@@ -68,6 +68,8 @@ source "drivers/watchdog/Kconfig"
 
 source "drivers/ssb/Kconfig"
 
+source "drivers/brcmaxi/Kconfig"
+
 source "drivers/mfd/Kconfig"
 
 source "drivers/regulator/Kconfig"
drivers/Makefile +1 -0
index a125e0b..c970b92 100644
@@ -110,6 +110,7 @@ obj-$(CONFIG_HID)		+= hid/
 obj-$(CONFIG_PPC_PS3)		+= ps3/
 obj-$(CONFIG_OF)		+= of/
 obj-$(CONFIG_SSB)		+= ssb/
+obj-$(CONFIG_BRCMAXI)		+= brcmaxi/
 obj-$(CONFIG_VHOST_NET)		+= vhost/
 obj-$(CONFIG_VLYNQ)		+= vlynq/
 obj-$(CONFIG_STAGING)		+= staging/
drivers/brcmaxi/Kconfig new file +23 -0
new file mode 100644
index 0000000..d5e384b
@@ -0,0 +1,23 @@
+menuconfig BRCMAXI
+	tristate "Broadcom AXI utility function module"
+	---help---
+	  This module provides utility functions for detecting, enabling,
+	  initializing, and configuring cores on Broadcom chips which are
+	  using the AMBA AXI bus.
+	  
+	  The module is called brcmaxi.ko.
+
+config BRCMAXI_AMBA
+	bool "Broadcom AXI direct access"
+	default y
+	depends on BRCMAXI
+	---help---
+	  Selecting Y here allows direct access to the cores on the AMBA
+	  AXI backplane.
+
+config BRCMAXI_PCI
+	bool "Broadcom AXI over PCI"
+	depends on BRCMAXI
+	---help---
+	  Selecting Y here allows access to cores on AMBA AXI backplane
+	  through the PCI host interface.
drivers/brcmaxi/Makefile new file +25 -0
new file mode 100644
index 0000000..91f7797
@@ -0,0 +1,25 @@
+#
+# Makefile for Broadcom AMBA AXI utility module
+#
+# Copyright (c) 2011 Broadcom Corporation
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+MODULEPFX := brcmaxi
+
+ccflags-$(CONFIG_DEBUG_KERNEL)		+= -DDEBUG
+
+obj-$(CONFIG_BRCMAXI)			+= $(MODULEPFX).o
+
+$(MODULEPFX)-y				+= axi.o
+$(MODULEPFX)-$(CONFIG_BRCMAXI_PCI)	+= pci.o
drivers/brcmaxi/axi.c new file +786 -0

786 lines not on this page · raw message

drivers/brcmaxi/axi_priv.h new file +51 -0

51 lines not on this page · raw message

drivers/brcmaxi/pci.c new file +118 -0

118 lines not on this page · raw message

include/brcmaxi/amba.h new file +87 -0

87 lines not on this page · raw message

include/brcmaxi/axi.h new file +310 -0

310 lines not on this page · raw message

include/brcmaxi/pci.h new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH 1/1] drivers: brcmaxi: provide amba axi functionality in separate module

Quoted 3 lines · Arend van Spriel
drivers/brcmaxi/axi.c new file +0 -0
@@ -0,0 +1,786 @@

...

drivers/brcmaxi/axi.c line 114

Quoted 12 lines
drivers/brcmaxi/axi.c new file +12 -0
+/* resetctrl */
+#define	AIRC_RESET		1
+
+/* definition for specifying padding fields */
+#define	_PADLINE(line)	pad ## line
+#define	_XSTR(line)	_PADLINE(line)
+#define	PAD		_XSTR(__LINE__)
+
+/*
+ * struct aidmp - device management plugin "wrapper" registers.
+ */
+struct aidmp {

This looks like it should be __packed__.

Quoted 3 lines
drivers/brcmaxi/axi.c new file +3 -0
+	u32 oobselina30;	/* 0x000 */
+	u32 oobselina74;	/* 0x004 */
+	u32 PAD[6];

...

Quoted 1 line

+};

...

drivers/brcmaxi/axi.c line 421

Quoted 6 lines
drivers/brcmaxi/axi.c new file +6 -0
+struct axi_local *axi_create(u32 priv_len)
+{
+	struct axi_local *inst;
+	int size = ALIGN(sizeof(*inst), 4) + priv_len;
+
+	inst = kzalloc(size, GFP_ATOMIC);

Hmm, ATOMIC without checking the retval. This is prepared for its first crash under a high memory pressure.

Quoted 4 lines
drivers/brcmaxi/axi.c new file +4 -0
+	try_module_get(THIS_MODULE);
+
+	return inst;
+}

drivers/brcmaxi/axi.c line 435

Quoted 10 lines
drivers/brcmaxi/axi.c new file +10 -0
+struct axi_instance *axi_open(void *regs, u32 erombase, u32 priv_len)
+{
+	struct axi_local *inst = axi_create(priv_len);
+
+	/* fill public fields */
+	inst->pub.regs = regs;
+	inst->pub.priv = (char *)inst + ALIGN(sizeof(*inst), 4);
+
+	inst->enum_rom_ptr = ioremap_nocache((unsigned long)erombase,
+					     AXI_CORE_SIZE);

Check retval.

drivers/brcmaxi/axi.c

Quoted 2 lines
drivers/brcmaxi/axi.c new file +2 -0
+	return &inst->pub;
+}

...

regards,

Signature · 2 lines
js
suse labs
#10 lore raw
In reply to Arend van Spriel
Quoted 15 lines · Arend van Spriel

GUIDANCE NEEDED:
This patch puts the module at proposed location. Please provide your guidance if there is a better location within the linux tree for this module.

This module has been isolated from the brcm80211 driver currently located in staging and provided to other drivers for chipsets using the AMBA AXI on-chip interconnect with ARM Device Management Plugin (DMP) silicon IP, which provides system discovery (chip being the system) and basic core function (disable, reset, etc.).

The module has previously been posted on the linux-wireless list and comments by Randy Dunlap have been taken in. Also the SubmitChecklist has been followed.

Quoted 6 lines

Arend van Spriel (1):
drivers: brcmaxi: provide amba axi functionality in separate module

 drivers/Kconfig            |    2 +
 drivers/Makefile           |    1 +
 drivers/brcmaxi/Kconfig    |   23 ++

I thought this was going under drivers/staging/ What changed your mind? What other drivers are going to use this, I thought the current broadcom drivers in drivers/net/wireless were not going to need this.

thanks,

greg k-h

#11 lore raw
In reply to Arend van Spriel
Quoted 10 lines · Arend van Spriel

GUIDANCE NEEDED:
This patch puts the module at proposed location. Please provide your guidance if there is a better location within the linux tree for this module.

This module has been isolated from the brcm80211 driver currently located in staging and provided to other drivers for chipsets using the AMBA AXI on-chip interconnect with ARM Device Management Plugin (DMP) silicon IP, which provides system discovery (chip being the system) and basic core function (disable, reset, etc.).

What does this do which the 'amba' bus support doesn't?

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
#17 lore raw
In reply to Arend van Spriel
Quoted 10 lines · Arend van Spriel

GUIDANCE NEEDED:
This patch puts the module at proposed location. Please provide your guidance if there is a better location within the linux tree for this module.

This module has been isolated from the brcm80211 driver currently located in staging and provided to other drivers for chipsets using the AMBA AXI on-chip interconnect with ARM Device Management Plugin (DMP) silicon IP, which provides system discovery (chip being the system) and basic core function (disable, reset, etc.).

Any reason this is not integrated with drivers/amba?

#18 lore raw
In reply to Arend van Spriel
Quoted 10 lines · Arend van Spriel

GUIDANCE NEEDED:
This patch puts the module at proposed location. Please provide your guidance if there is a better location within the linux tree for this module.

This module has been isolated from the brcm80211 driver currently located in staging and provided to other drivers for chipsets using the AMBA AXI on-chip interconnect with ARM Device Management Plugin (DMP) silicon IP, which provides system discovery (chip being the system) and basic core function (disable, reset, etc.).

Second point is this series has not been copied to the ARM mailing lists, so almost no one there has any clue that this is being proposed. Please post it to the ARM kernel mailing list so that all interested parties can review it, along with an explaination about why the existing AMBA primecell support can't be augmented to provide whatever functionality you require.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
#3 lore raw

Re: [PATCH 1/1] drivers: brcmaxi: provide amba axi functionality in separate module

In reply to Jiri Slaby
Quoted 5 lines · Jiri Slaby
Quoted 3 lines · Arend van Spriel
drivers/brcmaxi/axi.c new file +0 -0
@@ -0,0 +1,786 @@

...

Quoted 14 lines

drivers/brcmaxi/axi.c line 114

Quoted 12 lines
drivers/brcmaxi/axi.c new file +12 -0
+/* resetctrl */
+#define	AIRC_RESET		1
+
+/* definition for specifying padding fields */
+#define	_PADLINE(line)	pad ## line
+#define	_XSTR(line)	_PADLINE(line)
+#define	PAD		_XSTR(__LINE__)
+
+/*
+ * struct aidmp - device management plugin "wrapper" registers.
+ */
+struct aidmp {

This looks like it should be __packed__.

Why that? Adding the packed attribute would enforce byte access but not change the layout of the structure, so I think that would make it worse not better.

Arnd

#12 lore raw
In reply to Russell King
Quoted 6 lines · Russell King
Quoted 5 lines · Arend van Spriel

GUIDANCE NEEDED:
This patch puts the module at proposed location. Please provide your guidance if there is a better location within the linux tree for this module.

Quoted 7 lines
Quoted 5 lines

This module has been isolated from the brcm80211 driver currently located in staging and provided to other drivers for chipsets using the AMBA AXI on-chip interconnect with ARM Device Management Plugin (DMP) silicon IP, which provides system discovery (chip being the system) and basic core function (disable, reset, etc.).

What does this do which the 'amba' bus support doesn't?

I believe the one thing we really want from this driver is the bus scan code, which is not present in the amba bus implementation, as far as I can tell. Today, the amba bus does very little beyond what the platform bus does, in particular you still need to register every single device from board specific code.

When the proposed axi_scan() function gets turned into an amba_bus_register() function, a board file can call that to add all devices on the bus without listing them individually and calling amba_device_register() for each one.

Basically everything else is already there in the amba bus, no need to do it again.

Arnd

#13 lore raw
Quoted 6 lines · Arnd Bergmann

I believe the one thing we really want from this driver is the bus scan code, which is not present in the amba bus implementation, as far as I can tell. Today, the amba bus does very little beyond what the platform bus does, in particular you still need to register every single device from board specific code.

Quoted 7 lines

When the proposed axi_scan() function gets turned into an amba_bus_register() function, a board file can call that to add all devices on the bus without listing them individually and calling amba_device_register() for each one.

Basically everything else is already there in the amba bus, no need to do it again.

The reason we don't do automatic scanning (which we could on the various ARM platforms) is because of the platform data necessary to make some of the primecell drivers work.

Unfortunately, these buses are not as simple as PCI, where a device typically sits on its own card and is totally self-contained. With primecell stuff, there's normally some interdependencies between the various primecells.

That doesn't stop there being an automatic enumeration layer, but such a layer would need some way of attaching platform specific data to specific amba devices.

#14 lore raw
Quoted 4 lines · On Wednesday 30 March 2011 19:40:10 Russell King - ARM Linux wrote:

The reason we don't do automatic scanning (which we could on the various ARM platforms) is because of the platform data necessary to make some of the primecell drivers work.

Quoted 8 lines

Unfortunately, these buses are not as simple as PCI, where a device typically sits on its own card and is totally self-contained. With primecell stuff, there's normally some interdependencies between the various primecells.

That doesn't stop there being an automatic enumeration layer, but such a layer would need some way of attaching platform specific data to specific amba devices.

Right, I understand that this would not completely remove the need for platform devices, but I think it would be a great step in the right direction if we could scan all simple devices automatically, or possibly even all devices in some simple machines.

If we can scan the main resources (memory ranges, interrupts, ...), that will make it possible to avoid a whole lot of the stuff we currently do for each new board. It also means we can gradually move away from statically defined devices, something that Greg has been pushing for quite some time.

The device tree work has shown that it's possible to describe very complex hardware in simple data structures, but it would be much better if we needed neither a device tree nor a board file for this. As you say, this isn't possible today with the data on available to the AMBA bus, but I think it would be better to just fill in the blanks (and corrections where they are wrong) than to duplicate all of it as we now do in the kernel.

Ideally, we would point SoC companies to this (or a future extended version) as the place to add all the required information when they want the drivers to work out of the box. My impression is that there is no fundamental difference to buses like PCI or USB, other than that there is more data required to encode and that there is a lack of social pressure to get it right. I remember PCI cards from the 1990s that could not be probed properly and required setting a lot of module parameters copied from a web site depending on what hardware you had bought. The reason we don't have that as much today is that the manufacturers realized that it's impossible to write proper drivers if you cannot detect the hardware.

Arnd

#15 lore raw
Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · On Wednesday 30 March 2011 19:40:10 Russell King - ARM Linux wrote:

The reason we don't do automatic scanning (which we could on the various ARM platforms) is because of the platform data necessary to make some of the primecell drivers work.

Unfortunately, these buses are not as simple as PCI, where a device typically sits on its own card and is totally self-contained. With primecell stuff, there's normally some interdependencies between the various primecells.

Quoted 8 lines
Quoted 3 lines

That doesn't stop there being an automatic enumeration layer, but such a layer would need some way of attaching platform specific data to specific amba devices.

Right, I understand that this would not completely remove the need for platform devices, but I think it would be a great step in the right direction if we could scan all simple devices automatically, or possibly even all devices in some simple machines.

I'm not talking about platform devices at all. I'm talking about the data which platforms need to supply to their drivers in order for the drivers to work.

Eg, how the DMA is connected (or indeed whether the DMA signals are even connected in the first place). Where the card detect signal is for the MMC slot for the particular controller we've found, etc.

It's not as simple as (eg) detecting a MMC controller and immediately pointing it at the GPIO number - the "simple" ARM dev platforms normally have two MMC controllers so that needs to be distinguished.

This kind of data is precisely why I went down the static declaration route for all ARM dev platforms, despite most devices being trivially discoverable. I couldn't work out a decent way to automatically scan the devices while ensuring that the right platform specific driver data was attached to its correct device.

Quoted 3 lines

The device tree work has shown that it's possible to describe very complex hardware in simple data structures, but it would be much better if we needed neither a device tree nor a board file for this.

The device tree goes against automatic device discovery - unless you have a shim which runs before the kernel executes to adjust the device tree appropriately. Otherwise, I can't see anyway you could cope with (eg) a platform having MMC controllers at 0x10004000 and 0x10008000, and another with just one MMC controller at 0x10008000 but using the card detect lines from 0x10004000.

Quoted 6 lines

I remember PCI cards
from the 1990s that could not be probed properly and required setting a lot of module parameters copied from a web site depending on what hardware you had bought. The reason we don't have that as much today is that the manufacturers realized that it's impossible to write proper drivers if you cannot detect the hardware.

I think you're going to be waiting a very long time for that to happen. No SoC vendor adds device IDs to their on-chip devices to allow them to be automatically discovered - it's only through ARM Ltd's development of their Primecells, and then vendors integrating those into their SoC (maybe with their own modifications) that we've started to see this kind of ID system appearing.

Outside of the Primecell stuff, I'm unaware of anyone adding any kind of discovery mechanism to SoC based devices.

So, all in all I don't think that the automatic discovery idea is worth the effort. All that I can see is it causing lots of problems.

#4 lore raw

Re: [PATCH 1/1] drivers: brcmaxi: provide amba axi functionality in separate module

In reply to Arnd Bergmann
Quoted 21 lines · Arnd Bergmann
Quoted 5 lines · Jiri Slaby
Quoted 3 lines · Arend van Spriel
drivers/brcmaxi/axi.c new file +0 -0
@@ -0,0 +1,786 @@

...

Quoted 14 lines

drivers/brcmaxi/axi.c line 114

Quoted 12 lines
drivers/brcmaxi/axi.c new file +12 -0
+/* resetctrl */
+#define	AIRC_RESET		1
+
+/* definition for specifying padding fields */
+#define	_PADLINE(line)	pad ## line
+#define	_XSTR(line)	_PADLINE(line)
+#define	PAD		_XSTR(__LINE__)
+
+/*
+ * struct aidmp - device management plugin "wrapper" registers.
+ */
+struct aidmp {

This looks like it should be __packed__.

Quoted 3 lines

Why that? Adding the packed attribute would enforce byte access but not change the layout of the structure, so I think that would make it worse not better.

How it can? Packed only tells the compiler to have one byte alignment steps. And it should not matter here as all the members are 32-bit long.

The structure seems to be something which maps to device registers. So for documentation purposes it should be packed. And to avoid later mistakes when the u32 are broken down to u8s and u16s.

regards,

Signature · 2 lines
js
suse labs
#5 lore raw

Re: [PATCH 1/1] drivers: brcmaxi: provide amba axi functionality in separate module

Quoted 2 lines · Jiri Slaby

How it can? Packed only tells the compiler to have one byte alignment steps. And it should not matter here as all the members are 32-bit long.

It also tells the compiler that it may be misaligned, so to avoid alignment faults it will use byte loads/stores.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
#6 lore raw

Re: [PATCH 1/1] drivers: brcmaxi: provide amba axi functionality in separate module

Quoted 6 lines · Russell King
Quoted 2 lines · Jiri Slaby

How it can? Packed only tells the compiler to have one byte alignment steps. And it should not matter here as all the members are 32-bit long.

It also tells the compiler that it may be misaligned, so to avoid alignment faults it will use byte loads/stores.

No, it should not (if offsetof % sizeof == 0). Otherwise it's a bug in the compiler.

Am I missing something?

thanks,

Signature · 2 lines
js
suse labs
#7 lore raw

Re: [PATCH 1/1] drivers: brcmaxi: provide amba axi functionality in separate module

Quoted 5 lines · Jiri Slaby
Quoted 4 lines · Russell King
Quoted 2 lines · Jiri Slaby

How it can? Packed only tells the compiler to have one byte alignment steps. And it should not matter here as all the members are 32-bit long.

Quoted 7 lines
Quoted 2 lines

It also tells the compiler that it may be misaligned, so to avoid alignment faults it will use byte loads/stores.

No, it should not (if offsetof % sizeof == 0). Otherwise it's a bug in the compiler.

Am I missing something?

$ cat t1.c
struct foo {
        unsigned long bar;
} __attribute__((packed));

unsigned long baz(struct foo *f)

{
        return f->bar;
}
$ arm-linux-gcc -O2 -S -o - t1.c
...
        .global baz
        .type   baz, %function
baz:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        ldrb    r3, [r0, #0]    @ zero_extendqisi2
        ldrb    r2, [r0, #1]    @ zero_extendqisi2
        ldrb    r1, [r0, #2]    @ zero_extendqisi2
        orr     r3, r3, r2, asl #8
        ldrb    r0, [r0, #3]    @ zero_extendqisi2
        orr     r3, r3, r1, asl #16
        orr     r0, r3, r0, asl #24
        mov     pc, lr
        .size   baz, .-baz
        .ident  "GCC: (GNU) 4.3.5"
        .section        .note.GNU-stack,"",%progbits

It does this because with the packed attribute, it can't make assumptions about the alignment of 'f'.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
#8 lore raw

Re: [PATCH 1/1] drivers: brcmaxi: provide amba axi functionality in separate module

Quoted 43 lines · Russell King
Quoted 5 lines · Jiri Slaby
Quoted 4 lines · Russell King
Quoted 2 lines · Jiri Slaby

How it can? Packed only tells the compiler to have one byte alignment steps. And it should not matter here as all the members are 32-bit long.

Quoted 7 lines
Quoted 2 lines

It also tells the compiler that it may be misaligned, so to avoid alignment faults it will use byte loads/stores.

No, it should not (if offsetof % sizeof == 0). Otherwise it's a bug in the compiler.

Am I missing something?

$ cat t1.c
struct foo {
        unsigned long bar;
} __attribute__((packed));

unsigned long baz(struct foo *f)

{
        return f->bar;
}
$ arm-linux-gcc -O2 -S -o - t1.c
...
        .global baz
        .type   baz, %function
baz:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        ldrb    r3, [r0, #0]    @ zero_extendqisi2
        ldrb    r2, [r0, #1]    @ zero_extendqisi2
        ldrb    r1, [r0, #2]    @ zero_extendqisi2
        orr     r3, r3, r2, asl #8
        ldrb    r0, [r0, #3]    @ zero_extendqisi2
        orr     r3, r3, r1, asl #16
        orr     r0, r3, r0, asl #24
        mov     pc, lr
        .size   baz, .-baz
        .ident  "GCC: (GNU) 4.3.5"
        .section        .note.GNU-stack,"",%progbits
Quoted 2 lines

It does this because with the packed attribute, it can't make assumptions about the alignment of 'f'.

I don't see why it couldn't like without the packed attribute. (The manual says packed attribute for a struct is equivalent to specifying packed to each member of that struct. It doesn't say anything about the structure alignment itself.)

Ok, not that I'm fully convinced, but it doesn't matter.

So let's NOT mark it packed.

Anyway the info you sent was useful for me.

thanks,

Signature · 2 lines
js
suse labs
#9 lore raw

Re: [PATCH 1/1] drivers: brcmaxi: provide amba axi functionality in separate module

Quoted 4 lines · Jiri Slaby

I don't see why it couldn't like without the packed attribute. (The manual says packed attribute for a struct is equivalent to specifying packed to each member of that struct. It doesn't say anything about the structure alignment itself.)

To give some more background, any variable that is marked packed is assumed to be potentially unaligned (byte aligned). If a struct contains only members with byte alignment, it too is byte aligned.

Arnd

#16 lore raw
In reply to Russell King - ARM Linux
Quoted 16 lines · Russell King - ARM Linux
Quoted 15 lines · Arnd Bergmann
Quoted 12 lines · On Wednesday 30 March 2011 19:40:10 Russell King - ARM Linux wrote:

The reason we don't do automatic scanning (which we could on the various ARM platforms) is because of the platform data necessary to make some of the primecell drivers work.

Unfortunately, these buses are not as simple as PCI, where a device typically sits on its own card and is totally self-contained. With primecell stuff, there's normally some interdependencies between the various primecells.

That doesn't stop there being an automatic enumeration layer, but such a layer would need some way of attaching platform specific data to specific amba devices.

Quoted 8 lines
Quoted 4 lines

Right, I understand that this would not completely remove the need for platform devices, but I think it would be a great step in the right direction if we could scan all simple devices automatically, or possibly even all devices in some simple machines.

I'm not talking about platform devices at all. I'm talking about the data which platforms need to supply to their drivers in order for the drivers to work.

Yes, I meant platform_data, not platform_device.

Quoted 5 lines

This kind of data is precisely why I went down the static declaration route for all ARM dev platforms, despite most devices being trivially discoverable. I couldn't work out a decent way to automatically scan the devices while ensuring that the right platform specific driver data was attached to its correct device.

Maybe we can look at this again. The device tree scanning code is able to connect properties from the device tree to e.g. PCI devices that are probed from hardware. It may not be easy to do, but my feeling is that there is a lot to gain if we manage to do it.

Quoted 10 lines
Quoted 3 lines

The device tree work has shown that it's possible to describe very complex hardware in simple data structures, but it would be much better if we needed neither a device tree nor a board file for this.

The device tree goes against automatic device discovery - unless you have a shim which runs before the kernel executes to adjust the device tree appropriately. Otherwise, I can't see anyway you could cope with (eg) a platform having MMC controllers at 0x10004000 and 0x10008000, and another with just one MMC controller at 0x10008000 but using the card detect lines from 0x10004000.

The device tree is just another way to do automatic device discovery. Fundamentally there is not much difference between reading data in a fixed format from a PCI config space, a hardware ROM on AMBA or a blob passed into the kernel.

The disadvantage of the device tree is that it's harder to get it to match the actual hardware, while the advantage is that it's flexible enough to describe the example you just gave.

As I mentioned above, it's possible to describe devices in the device tree format that are also detected from hardware scanning, and to combine information from both sources.

If the information in the hardware is complete, as is usually the case on PCI or USB buses, the device trees we use on other architectures only list the root node of a bus that gets scanned in hardware.

Quoted 14 lines
Quoted 6 lines

I remember PCI cards
from the 1990s that could not be probed properly and required setting a lot of module parameters copied from a web site depending on what hardware you had bought. The reason we don't have that as much today is that the manufacturers realized that it's impossible to write proper drivers if you cannot detect the hardware.

I think you're going to be waiting a very long time for that to happen. No SoC vendor adds device IDs to their on-chip devices to allow them to be automatically discovered - it's only through ARM Ltd's development of their Primecells, and then vendors integrating those into their SoC (maybe with their own modifications) that we've started to see this kind of ID system appearing.

Quoted 2 lines

Outside of the Primecell stuff, I'm unaware of anyone adding any kind of discovery mechanism to SoC based devices.

I'm willing to try to keep pushing for it, once I figure out where ;-)

If we have support for automatic probing of some devices in the kernel, that might be a way to convince hardware vendors that simply putting correct information in the hardware can improve their time to market, which directly translates into money.

Arnd