From patchwork Fri Oct 14 10:04:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 4680 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 7AB4E23EFA for ; Fri, 14 Oct 2011 10:05:15 +0000 (UTC) Received: from mail-yx0-f174.google.com (mail-yx0-f174.google.com [209.85.213.174]) by fiordland.canonical.com (Postfix) with ESMTP id 451ACA18777 for ; Fri, 14 Oct 2011 10:05:15 +0000 (UTC) Received: by mail-yx0-f174.google.com with SMTP id 4so693373yxp.19 for ; Fri, 14 Oct 2011 03:05:15 -0700 (PDT) Received: by 10.223.60.73 with SMTP id o9mr3149367fah.18.1318586714784; Fri, 14 Oct 2011 03:05:14 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.24.41 with SMTP id r9cs8409laf; Fri, 14 Oct 2011 03:05:14 -0700 (PDT) Received: by 10.216.133.160 with SMTP id q32mr1263153wei.108.1318586712652; Fri, 14 Oct 2011 03:05:12 -0700 (PDT) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx.google.com with ESMTPS id fv8si5542883wbb.91.2011.10.14.03.05.12 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 14 Oct 2011 03:05:12 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.50 is neither permitted nor denied by best guess record for domain of dave.martin@linaro.org) client-ip=74.125.82.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.50 is neither permitted nor denied by best guess record for domain of dave.martin@linaro.org) smtp.mail=dave.martin@linaro.org Received: by mail-ww0-f50.google.com with SMTP id 3so3015964wwe.31 for ; Fri, 14 Oct 2011 03:05:12 -0700 (PDT) Received: by 10.216.230.157 with SMTP id j29mr1312264weq.67.1318586711774; Fri, 14 Oct 2011 03:05:11 -0700 (PDT) Received: from e103592.peterhouse.linaro.org (fw-lnat.cambridge.arm.com. [217.140.96.63]) by mx.google.com with ESMTPS id g20sm13249463wbp.13.2011.10.14.03.05.09 (version=SSLv3 cipher=OTHER); Fri, 14 Oct 2011 03:05:10 -0700 (PDT) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: patches@linaro.org, linux-arm-kernel@lists.infradead.org, Dave Martin Subject: [PATCH 2/2] ARM: amba: Auto-generate AMBA driver module aliases during modpost Date: Fri, 14 Oct 2011 11:04:51 +0100 Message-Id: <1318586691-3833-3-git-send-email-dave.martin@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1318586691-3833-1-git-send-email-dave.martin@linaro.org> References: <1318586691-3833-1-git-send-email-dave.martin@linaro.org> 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 Acked-by: Pawel Moll --- 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); }