* [PATCH 0/2] ARM: amba: Enable module alias autogeneration for AMBA drivers
@ 2011-10-14 10:04 Dave Martin
2011-10-14 10:04 ` [PATCH 1/2] ARM: amba: Move definition of struct amba_id to mod_devicetable.h Dave Martin
2011-10-14 10:04 ` [PATCH 2/2] ARM: amba: Auto-generate AMBA driver module aliases during modpost Dave Martin
0 siblings, 2 replies; 3+ messages in thread
From: Dave Martin @ 2011-10-14 10:04 UTC (permalink / raw)
To: linux-arm-kernel
[This is a partial repost of a series previously posted to alkml.
This post contains the core changes. The driver-specific changes
can be found on alkml.]
--
There's no special reason why AMBA device drivers should not be
auto-loadable via udev, but udev currently has no way to map AMBA
device IDs to drivers.
As part of the effort to help enable the building of multiple
ARM platforms into a single kernel image in the future, it's desirable
to be able to build any non-critical platform-specific drivers as
modules.
A straightforward solution is to use modaliases to allow udev to
identify the correct driver module to load.
This series enables the general infrastructure for modalias generation
to work for AMBA devices, and enables it in the affected drivers.
Briefly tested on Versatile Express, including aaci, mmci and amba-clcd
(which appears to have the most interesting modalias match pattern).
For me, the appropiate modules now get loaded at udev trigger time.
Any comments and feedback are welcome.
Dave Martin (2):
ARM: amba: Move definition of struct amba_id to mod_devicetable.h
ARM: amba: Auto-generate AMBA driver module aliases during modpost
drivers/amba/bus.c | 9 ++++-
include/linux/amba/bus.h | 7 +---
include/linux/mod_devicetable.h | 18 ++++++++++
scripts/mod/file2alias.c | 72 +++++++++++++++++++++++++++++++++++++++
4 files changed, 99 insertions(+), 7 deletions(-)
--
1.7.4.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] ARM: amba: Move definition of struct amba_id to mod_devicetable.h
2011-10-14 10:04 [PATCH 0/2] ARM: amba: Enable module alias autogeneration for AMBA drivers Dave Martin
@ 2011-10-14 10:04 ` Dave Martin
2011-10-14 10:04 ` [PATCH 2/2] ARM: amba: Auto-generate AMBA driver module aliases during modpost Dave Martin
1 sibling, 0 replies; 3+ messages in thread
From: Dave Martin @ 2011-10-14 10:04 UTC (permalink / raw)
To: linux-arm-kernel
The general kernel infrastructure for adding module alises during
module post processing expects the affected device type
identification structures in a common header
<linux/mod_devicetable.h>.
This patch simple moves struct amba_id to the common header, and
adds the appropriate include in <linux/amba/bus.h>.
Signed-off-by: Dave Martin <dave.martin@linaro.org>
---
include/linux/amba/bus.h | 7 +------
include/linux/mod_devicetable.h | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
index fcbbe71..724c69c 100644
--- a/include/linux/amba/bus.h
+++ b/include/linux/amba/bus.h
@@ -16,6 +16,7 @@
#include <linux/clk.h>
#include <linux/device.h>
+#include <linux/mod_devicetable.h>
#include <linux/err.h>
#include <linux/resource.h>
#include <linux/regulator/consumer.h>
@@ -35,12 +36,6 @@ struct amba_device {
unsigned int irq[AMBA_NR_IRQS];
};
-struct amba_id {
- unsigned int id;
- unsigned int mask;
- void *data;
-};
-
struct amba_driver {
struct device_driver drv;
int (*probe)(struct amba_device *, const struct amba_id *);
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 468819c..83ac071 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -542,4 +542,22 @@ struct isapnp_device_id {
kernel_ulong_t driver_data; /* data private to the driver */
};
+/**
+ * struct amba_id - identifies a device on an AMBA bus
+ * @id: The significant bits if the hardware device ID
+ * @mask: Bitmask specifying which bits of the id field are significant when
+ * matching. A driver binds to a device when ((hardware device ID) & mask)
+ * == id.
+ * @data: Private data used by the driver.
+ */
+struct amba_id {
+ unsigned int id;
+ unsigned int mask;
+#ifndef __KERNEL__
+ kernel_ulong_t data;
+#else
+ void *data;
+#endif
+};
+
#endif /* LINUX_MOD_DEVICETABLE_H */
--
1.7.4.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] ARM: amba: Auto-generate AMBA driver module aliases during modpost
2011-10-14 10:04 [PATCH 0/2] ARM: amba: Enable module alias autogeneration for AMBA drivers Dave Martin
2011-10-14 10:04 ` [PATCH 1/2] ARM: amba: Move definition of struct amba_id to mod_devicetable.h Dave Martin
@ 2011-10-14 10:04 ` Dave Martin
1 sibling, 0 replies; 3+ messages in thread
From: Dave Martin @ 2011-10-14 10:04 UTC (permalink / raw)
To: linux-arm-kernel
This patch adds the necessary support in file2alias.c to define
suitable aliases based on the amba_id table in AMBA driver modules.
This should be sufficient to allow such modules to be auto-loaded
via udev. The AMBA bus driver's uevent hotplug code is also
modified to pass an approriate MODALIAS string in the event.
For simplicity, the AMBA ID is treated an an opaque 32-bit numeber.
Module alises use patterns as appropriate to describe the value-
mask pairs described in the driver's amba_id list.
The proposed alias format is (extended regex):
^amba:d(HEX){8}$
Where HEX is a single upper-case HEX digit or a pattern (? or []
expression) matching a single upper-case HEX digit, as expected by
udev.
"d" is short for "device", following existing alias naming
conventions for other device types. This adds some flexibility for
unambiguously extending the alias format in the future by adding
additional leading and trailing fields, if this turns out to be
necessary.
Signed-off-by: Dave Martin <dave.martin@linaro.org>
Acked-by: Pawel Moll <pawel.moll@arm.com>
---
drivers/amba/bus.c | 9 +++++-
scripts/mod/file2alias.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 1 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index bd230e8..a8c598c 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -52,7 +52,14 @@ static int amba_uevent(struct device *dev, struct kobj_uevent_env *env)
int retval = 0;
retval = add_uevent_var(env, "AMBA_ID=%08x", pcdev->periphid);
- return retval;
+ if (retval)
+ return retval;
+
+ retval = add_uevent_var(env, "MODALIAS=amba:d%08X", pcdev->periphid);
+ if (retval)
+ return retval;
+
+ return 0;
}
#else
#define amba_uevent NULL
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index f936d1f..363ab46 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -880,6 +880,74 @@ static int do_isapnp_entry(const char *filename,
return 1;
}
+/*
+ * Append a match expression for a single masked hex digit.
+ * outp points to a pointer to the character at which to append.
+ * *outp is updated on return to point just after the appended text,
+ * to facilitate further appending.
+ */
+static void append_nibble_mask(char **outp,
+ unsigned int nibble, unsigned int mask)
+{
+ char *p = *outp;
+ unsigned int i;
+
+ switch (mask) {
+ case 0:
+ *p++ = '?';
+ break;
+
+ case 0xf:
+ p += sprintf(p, "%X", nibble);
+ break;
+
+ default:
+ /*
+ * Dumbly emit a match pattern for all possible matching
+ * digits. This could be improved in some cases using ranges,
+ * but it has the advantage of being trivially correct, and is
+ * often optimal.
+ */
+ *p++ = '[';
+ for (i = 0; i < 0x10; i++)
+ if ((i & mask) == nibble)
+ p += sprintf(p, "%X", i);
+ *p++ = ']';
+ }
+
+ /* Ensure that the string remains NUL-terminated: */
+ *p = '\0';
+
+ /* Advance the caller's end-of-string pointer: */
+ *outp = p;
+}
+
+/*
+ * looks like: "amba:dN"
+ *
+ * N is exactly 8 digits, where each is an upper-case hex digit, or
+ * a ? or [] pattern matching exactly one digit.
+ */
+static int do_amba_entry(const char *filename,
+ struct amba_id *id, char *alias)
+{
+ unsigned int digit;
+ char *p = alias;
+
+ if ((id->id & id->mask) != id->id)
+ fatal("%s: Masked-off bit(s) of AMBA device ID are non-zero: "
+ "id=0x%08X, mask=0x%08X. Please fix this driver.\n",
+ filename, id->id, id->mask);
+
+ p += sprintf(alias, "amba:d");
+ for (digit = 0; digit < 8; digit++)
+ append_nibble_mask(&p,
+ (id->id >> (4 * (7 - digit))) & 0xf,
+ (id->mask >> (4 * (7 - digit))) & 0xf);
+
+ return 1;
+}
+
/* Ignore any prefix, eg. some architectures prepend _ */
static inline int sym_is(const char *symbol, const char *name)
{
@@ -1047,6 +1115,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
do_table(symval, sym->st_size,
sizeof(struct isapnp_device_id), "isa",
do_isapnp_entry, mod);
+ else if (sym_is(symname, "__mod_amba_device_table"))
+ do_table(symval, sym->st_size,
+ sizeof(struct amba_id), "amba",
+ do_amba_entry, mod);
free(zeros);
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-10-14 10:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-14 10:04 [PATCH 0/2] ARM: amba: Enable module alias autogeneration for AMBA drivers Dave Martin
2011-10-14 10:04 ` [PATCH 1/2] ARM: amba: Move definition of struct amba_id to mod_devicetable.h Dave Martin
2011-10-14 10:04 ` [PATCH 2/2] ARM: amba: Auto-generate AMBA driver module aliases during modpost Dave Martin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).