Skip to contentSkip to conversation

driver core: Add ability for arch code to setup pdev_archdata

PATCH In review Kumar Gala 3 participants 9 messages Aug 5, 2010

Subsystems (14)
Arm (32-bit) x86 PowerPC MIPS +10 more subsystems
lore
Share & tools
lore
author
#2 lore raw

PATCH 2/3 powerpc: implement arch_setup_pdev_archdata

In reply to Kumar Gala

We have a long standing issues with platform devices not have a valid dma_mask pointer. This hasn't been an issue to date as no platform device has tried to set its dma_mask value to a non-default value.

---
 arch/powerpc/include/asm/platform_device.h |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)
arch/powerpc/include/asm/platform_device.h +15 -1
index 01452c3..a379500 100644
@@ -1 +1,15 @@
-#include <asm-generic/platform_device.h>
+#ifndef __ASM_PLATFORM_DEVICE_H_
+#define __ASM_PLATFORM_DEVICE_H_
+
+#include <linux/platform_device.h>
+
+#define ARCH_HAS_PDEV_ARCHDATA_SETUP
+
+static inline void arch_setup_pdev_archdata(struct platform_device *pdev)
+{
+	pdev->dev.dma_mask = &pdev->archdata.dma_mask;
+
+	return;
+}
+
+#endif /* __ASM_GENERIC_PLATFORM_DEVICE_H_ */
Signature · 1 line
1.6.0.6
author
#3 lore raw

PATCH 3/3 powerpc: Dont require a dma_ops struct to set dma mask

The only reason to require a dma_ops struct is to see if it has implemented set_dma_mask. If not we can fall back to setting the mask directly.

This resolves an issue with how to sequence the setting of a DMA mask for platform devices. Before we had an issue in that we have no way of setting the DMA mask before the various low level bus notifiers get called that might check it (swiotlb).

So now we can do:

	pdev = platform_device_alloc("foobar", 0);
	dma_set_mask(&pdev->dev, DMA_BIT_MASK(37));
	platform_device_register(pdev);

And expect the right thing to happen with the bus notifiers get called via platform_device_register.

---
 arch/powerpc/include/asm/dma-mapping.h |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/dma-mapping.h +2 -4
index c85ef23..952208a 100644
@@ -131,12 +131,10 @@ static inline int dma_set_mask(struct device *dev, u64 dma_mask)
 {
 	struct dma_map_ops *dma_ops = get_dma_ops(dev);
 
-	if (unlikely(dma_ops == NULL))
-		return -EIO;
-	if (dma_ops->set_dma_mask != NULL)
-		return dma_ops->set_dma_mask(dev, dma_mask);
 	if (!dev->dma_mask || !dma_supported(dev, dma_mask))
 		return -EIO;
+	if (dma_ops && (dma_ops->set_dma_mask != NULL))
+		return dma_ops->set_dma_mask(dev, dma_mask);
 	*dev->dma_mask = dma_mask;
 	return 0;
 }
Signature · 1 line
1.6.0.6
author
#1 lore raw

PATCH 1/3 driver core: Add ability for arch code to setup pdev_archdata

In reply to Kumar Gala

On some architectures we need to setup pdev_archdata before we add the device. Waiting til a bus_notifier is too late since we might need the pdev_archdata in the bus notifier. One example is setting up of dma_mask pointers such that it can be used in a bus_notifier.

We add ARCH_HAS_PDEV_ARCHDATA_SETUP and a dummy <asm/platform_device.h> header to allow the arch code to have an inline implementation of arch_setup_pdev_archdata() and being able to access the full definitions of struct device, struct platform_device, and struct pdev_archdata.

---
 arch/alpha/include/asm/platform_device.h      |    1 +
 arch/arm/include/asm/platform_device.h        |    1 +
 arch/avr32/include/asm/platform_device.h      |    1 +
 arch/blackfin/include/asm/platform_device.h   |    1 +
 arch/cris/include/asm/platform_device.h       |    1 +
 arch/frv/include/asm/platform_device.h        |    1 +
 arch/h8300/include/asm/platform_device.h      |    1 +
 arch/ia64/include/asm/platform_device.h       |    1 +
 arch/m32r/include/asm/platform_device.h       |    1 +
 arch/m68k/include/asm/platform_device.h       |    1 +
 arch/microblaze/include/asm/platform_device.h |    1 +
 arch/mips/include/asm/platform_device.h       |    1 +
 arch/mn10300/include/asm/platform_device.h    |    1 +
 arch/parisc/include/asm/platform_device.h     |    1 +
 arch/powerpc/include/asm/platform_device.h    |    1 +
 arch/s390/include/asm/platform_device.h       |    1 +
 arch/score/include/asm/platform_device.h      |    1 +
 arch/sh/include/asm/platform_device.h         |    1 +
 arch/sparc/include/asm/platform_device.h      |    1 +
 arch/x86/include/asm/platform_device.h        |    1 +
 arch/xtensa/include/asm/platform_device.h     |    1 +
 drivers/base/platform.c                       |    4 ++++
 include/asm-generic/platform_device.h         |    7 +++++++
 23 files changed, 32 insertions(+), 0 deletions(-)
 create mode 100644 arch/alpha/include/asm/platform_device.h
 create mode 100644 arch/arm/include/asm/platform_device.h
 create mode 100644 arch/avr32/include/asm/platform_device.h
 create mode 100644 arch/blackfin/include/asm/platform_device.h
 create mode 100644 arch/cris/include/asm/platform_device.h
 create mode 100644 arch/frv/include/asm/platform_device.h
 create mode 100644 arch/h8300/include/asm/platform_device.h
 create mode 100644 arch/ia64/include/asm/platform_device.h
 create mode 100644 arch/m32r/include/asm/platform_device.h
 create mode 100644 arch/m68k/include/asm/platform_device.h
 create mode 100644 arch/microblaze/include/asm/platform_device.h
 create mode 100644 arch/mips/include/asm/platform_device.h
 create mode 100644 arch/mn10300/include/asm/platform_device.h
 create mode 100644 arch/parisc/include/asm/platform_device.h
 create mode 100644 arch/powerpc/include/asm/platform_device.h
 create mode 100644 arch/s390/include/asm/platform_device.h
 create mode 100644 arch/score/include/asm/platform_device.h
 create mode 100644 arch/sh/include/asm/platform_device.h
 create mode 100644 arch/sparc/include/asm/platform_device.h
 create mode 100644 arch/x86/include/asm/platform_device.h
 create mode 100644 arch/xtensa/include/asm/platform_device.h
 create mode 100644 include/asm-generic/platform_device.h
arch/alpha/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/arm/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/avr32/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/blackfin/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/cris/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/frv/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/h8300/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/ia64/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/m32r/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/m68k/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/microblaze/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/mips/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/mn10300/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/parisc/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/powerpc/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/s390/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/score/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/sh/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/sparc/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/x86/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
arch/xtensa/include/asm/platform_device.h new file +1 -0
new file mode 100644
index 0000000..01452c3
@@ -0,0 +1 @@
+#include <asm-generic/platform_device.h>
drivers/base/platform.c +4 -0
index 4d99c8b..165b454 100644
@@ -19,6 +19,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/pm_runtime.h>
+#include <asm/platform_device.h>
 
 #include "base.h"
 
@@ -170,6 +171,9 @@ struct platform_device *platform_device_alloc(const char *name, int id)
 		pa->pdev.id = id;
 		device_initialize(&pa->pdev.dev);
 		pa->pdev.dev.release = platform_device_release;
+#ifdef ARCH_HAS_PDEV_ARCHDATA_SETUP
+		arch_setup_pdev_archdata(&pa->pdev);
+#endif
 	}
 
 	return pa ? &pa->pdev : NULL;
include/asm-generic/platform_device.h new file +7 -0
new file mode 100644
index 0000000..64806dc
@@ -0,0 +1,7 @@
+#ifndef __ASM_GENERIC_PLATFORM_DEVICE_H_
+#define __ASM_GENERIC_PLATFORM_DEVICE_H_
+/*
+ * an architecture can override to define arch_setup_pdev_archdata
+ */
+
+#endif /* __ASM_GENERIC_PLATFORM_DEVICE_H_ */
Signature · 1 line
1.6.0.6

Kumar Gala

author
#0 lore raw

cover driver core: Add ability for arch code to setup pdev_archdata

On PPC we need to set the dma_mask pointer for platform_devices to point to the pdev_archdata. We can't wait for a bus_notifier as we need the dma_mask setup before the platform_device_add happens so that the bus_notifiers can check the dma_mask to determine if we need things like the SWIOTLB dma_ops.

The patch series introduces an arch specific call out (arch_setup_pdev_archdata) and provide an implementation on PPC to handle our specific issue.

- k

#6 lore raw
In reply to Kumar Gala

Hi Kumar,

Quoted 27 lines · On Thu, 5 Aug 2010 10:15:45 -0500 Kumar Gala <[email protected]> wrote:
drivers/base/platform.c +4 -0
@@ -19,6 +19,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/pm_runtime.h>
+#include <asm/platform_device.h>
 
 #include "base.h"
 
@@ -170,6 +171,9 @@ struct platform_device *platform_device_alloc(const char *name, int id)
 		pa->pdev.id = id;
 		device_initialize(&pa->pdev.dev);
 		pa->pdev.dev.release = platform_device_release;
+#ifdef ARCH_HAS_PDEV_ARCHDATA_SETUP
+		arch_setup_pdev_archdata(&pa->pdev);
+#endif
 	}
 
 	return pa ? &pa->pdev : NULL;
include/asm-generic/platform_device.h new file +0 -0
new file mode 100644
index 0000000..64806dc

include/asm-generic/platform_device.h line 7

Quoted 7 lines
include/asm-generic/platform_device.h new file +7 -0
@@ -0,0 +1,7 @@
+#ifndef __ASM_GENERIC_PLATFORM_DEVICE_H_
+#define __ASM_GENERIC_PLATFORM_DEVICE_H_
+/*
+ * an architecture can override to define arch_setup_pdev_archdata
+ */
+
+#endif /* __ASM_GENERIC_PLATFORM_DEVICE_H_ */

Why not do:

#include <linux/platform_device.h>

#ifndef arch_setup_pdev_archdata
static inline void arch_setup_pdev_archdata(struct platform_device *pdev) { } #endif

in asm-generic/platform-device.h

and the the call in platform_device_alloc() can be unconditional. If the arch wants to override arch_setup_pdev_archdata, it defines the function and then does

#define arch_setup_pdev_archdata arch_setup_pdev_archdata

before still including asm-generic/platform_device.h

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#4 lore raw

Re: [PATCH 2/3] powerpc: implement arch_setup_pdev_archdata

In reply to Kumar Gala

Hi Kumar,

arch/powerpc/include/asm/platform_device.h line 13

Quoted 7 lines · On Thu, 5 Aug 2010 10:15:46 -0500 Kumar Gala <[email protected]> wrote:
arch/powerpc/include/asm/platform_device.h +6 -0
+static inline void arch_setup_pdev_archdata(struct platform_device *pdev)
+{
+	pdev->dev.dma_mask = &pdev->archdata.dma_mask;
+
+	return;
+}

The blank line and "return;" don't add anything.

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
author
#5 lore raw

Re: [PATCH 2/3] powerpc: implement arch_setup_pdev_archdata

Quoted 3 lines · Stephen Rothwell

Hi Kumar,
=20
On Thu, 5 Aug 2010 10:15:46 -0500 Kumar Gala =

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines

=20
+static inline void arch_setup_pdev_archdata(struct platform_device =

*pdev)

Quoted 7 lines

arch/powerpc/include/asm/platform_device.h line 13

Quoted 5 lines
arch/powerpc/include/asm/platform_device.h +5 -0
+{
+	pdev->dev.dma_mask =3D &pdev->archdata.dma_mask;
+
+	return;
+}

=20
The blank line and "return;" don't add anything.

Will fix.

- k=

author
#7 lore raw
In reply to Stephen Rothwell
Quoted 3 lines · Stephen Rothwell

Hi Kumar,
=20
On Thu, 5 Aug 2010 10:15:45 -0500 Kumar Gala =

Quoted 4 lines · <[email protected]> wrote:
Quoted 4 lines

=20

drivers/base/platform.c +0 -0
@@ -19,6 +19,7 @@
Quoted 8 lines

drivers/base/platform.c struct platform_device =

Quoted 8 lines
drivers/base/platform.c +1 -0
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/pm_runtime.h>
+#include <asm/platform_device.h>

=20
#include "base.h"
=20

drivers/base/platform.c +0 -0
@@ -170,6 +171,9 @@ struct platform_device =

*platform_device_alloc(const char *name, int id)

Quoted 10 lines

=

Quoted 10 lines
drivers/base/platform.c +3 -0
 		pa->pdev.id =3D id;
 		device_initialize(&pa->pdev.dev);
 		pa->pdev.dev.release =3D platform_device_release;
+#ifdef ARCH_HAS_PDEV_ARCHDATA_SETUP
+		arch_setup_pdev_archdata(&pa->pdev);
+#endif
 	}

=20

	return pa ? &pa->pdev : NULL;
= renamed from include/asm-generic/platform_device.h +0 -0

b/include/asm-generic/platform_device.h

Quoted 11 lines
Quoted 11 lines

new file mode 100644
index 0000000..64806dc

include/asm-generic/platform_device.h new file +6 -0
@@ -0,0 +1,7 @@
+#ifndef __ASM_GENERIC_PLATFORM_DEVICE_H_
+#define __ASM_GENERIC_PLATFORM_DEVICE_H_
+/*
+ * an architecture can override to define arch_setup_pdev_archdata
+ */
+
Quoted 8 lines

include/asm-generic/platform_device.h line 7

Quoted 1 line
include/asm-generic/platform_device.h new file +1 -0
+#endif /* __ASM_GENERIC_PLATFORM_DEVICE_H_ */

=20
Why not do:
=20
#include <linux/platform_device.h>
=20
#ifndef arch_setup_pdev_archdata
static inline void arch_setup_pdev_archdata(struct platform_device =

*pdev) { }

Quoted 5 lines

#endif
=20
in asm-generic/platform-device.h
=20
and the the call in platform_device_alloc() can be unconditional. If =

the arch wants to override arch_setup_pdev_archdata, it defines the = function and then does

Quoted 4 lines

=20
#define arch_setup_pdev_archdata arch_setup_pdev_archdata =20
before still including asm-generic/platform_device.h

I've got no issues with the style change.

- k=

#8 lore raw
In reply to Stephen Rothwell
Quoted 46 lines · Stephen Rothwell

Hi Kumar,

Quoted 27 lines · On Thu, 5 Aug 2010 10:15:45 -0500 Kumar Gala <[email protected]> wrote:
drivers/base/platform.c +4 -0
@@ -19,6 +19,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/pm_runtime.h>
+#include <asm/platform_device.h>
 
 #include "base.h"
 
@@ -170,6 +171,9 @@ struct platform_device *platform_device_alloc(const char *name, int id)
 		pa->pdev.id = id;
 		device_initialize(&pa->pdev.dev);
 		pa->pdev.dev.release = platform_device_release;
+#ifdef ARCH_HAS_PDEV_ARCHDATA_SETUP
+		arch_setup_pdev_archdata(&pa->pdev);
+#endif
 	}
 
 	return pa ? &pa->pdev : NULL;
include/asm-generic/platform_device.h new file +0 -0
new file mode 100644
index 0000000..64806dc

include/asm-generic/platform_device.h line 7

Quoted 7 lines
include/asm-generic/platform_device.h new file +7 -0
@@ -0,0 +1,7 @@
+#ifndef __ASM_GENERIC_PLATFORM_DEVICE_H_
+#define __ASM_GENERIC_PLATFORM_DEVICE_H_
+/*
+ * an architecture can override to define arch_setup_pdev_archdata
+ */
+
+#endif /* __ASM_GENERIC_PLATFORM_DEVICE_H_ */

Why not do:

#include <linux/platform_device.h>

#ifndef arch_setup_pdev_archdata
static inline void arch_setup_pdev_archdata(struct platform_device *pdev) { } #endif

Quoted 7 lines

in asm-generic/platform-device.h

and the the call in platform_device_alloc() can be unconditional. If the arch wants to override arch_setup_pdev_archdata, it defines the function and then does

#define arch_setup_pdev_archdata arch_setup_pdev_archdata

before still including asm-generic/platform_device.h

Yes, I'd prefer that method as well.

thanks,

greg k-h