From patchwork Wed May 8 02:33:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 16753 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f198.google.com (mail-ve0-f198.google.com [209.85.128.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5A778238FD for ; Wed, 8 May 2013 02:35:16 +0000 (UTC) Received: by mail-ve0-f198.google.com with SMTP id 15sf1728942vea.9 for ; Tue, 07 May 2013 19:34:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=iS0ScEOO6WPUQTPY+zQqIpCDVNcw+kqYs+yRZs2bRFg=; b=bX533NdxG5MeTyrru1v9dpZcqrvV34dDz83VmpbUndUqGoOY7qSOzGi9eFgWVE+JJ9 ogDpDJuVfY+RSZJTDIY+/ackJrQ/RKVd2YbBAJ+ewaCpvaE50U0iz/jgy6XH553Z+hy5 aBxZYDGI6lwGndWZfu/XuwZMGMt/of1goU2i9k4w7oeuhhXAjlbMJ+IUH2PVLqPDrZ2b eenEhcvdwmBWnTH0PuJYNVmuKc6AQ1T019HR+1oTZyWXRDqounmqN6WqU0qq+cv9358f gQk3Zs0Oo+/a3SbGPc2C7rRJfugDG5Ow+1xuzY65EXUnelEntDhWIFlQUSSKaTism3/P fupQ== X-Received: by 10.236.72.129 with SMTP id t1mr2841749yhd.45.1367980496340; Tue, 07 May 2013 19:34:56 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.47.48 with SMTP id a16ls729148qen.25.gmail; Tue, 07 May 2013 19:34:56 -0700 (PDT) X-Received: by 10.52.182.71 with SMTP id ec7mr2468782vdc.64.1367980495977; Tue, 07 May 2013 19:34:55 -0700 (PDT) Received: from mail-vb0-x229.google.com (mail-vb0-x229.google.com [2607:f8b0:400c:c02::229]) by mx.google.com with ESMTPS id sc6si14152547vdc.47.2013.05.07.19.34.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 May 2013 19:34:55 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::229 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::229; Received: by mail-vb0-f41.google.com with SMTP id w8so1181229vbf.28 for ; Tue, 07 May 2013 19:34:55 -0700 (PDT) X-Received: by 10.220.82.68 with SMTP id a4mr3110496vcl.49.1367980495870; Tue, 07 May 2013 19:34:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp131018veb; Tue, 7 May 2013 19:34:55 -0700 (PDT) X-Received: by 10.180.105.195 with SMTP id go3mr18454207wib.2.1367980494827; Tue, 07 May 2013 19:34:54 -0700 (PDT) Received: from mail-we0-x232.google.com (mail-we0-x232.google.com [2a00:1450:400c:c03::232]) by mx.google.com with ESMTPS id bc5si8847846wjb.38.2013.05.07.19.34.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 May 2013 19:34:54 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::232 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=2a00:1450:400c:c03::232; Received: by mail-we0-f178.google.com with SMTP id q57so1209409wes.23 for ; Tue, 07 May 2013 19:34:54 -0700 (PDT) X-Received: by 10.180.185.179 with SMTP id fd19mr6960684wic.1.1367980494193; Tue, 07 May 2013 19:34:54 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id v6sm6823630wiy.11.2013.05.07.19.34.53 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 May 2013 19:34:53 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: Stefano.Stabellini@eu.citrix.com, patches@linaro.org, ian.campbell@citrix.com, Julien Grall Subject: [PATCH V2 18/33] xen/arm: Introduce a generic way to use a device from the device tree Date: Wed, 8 May 2013 03:33:38 +0100 Message-Id: <40fddd0a10e3b2f5d6c3da431377e17539eb10d1.1367979526.git.julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-Gm-Message-State: ALoCoQkQ9KPTLRKHx3CL0qNSh5CgmRkjyYRB0c+1Dc5uw04DCgdahI7PQpFaGgVUFIftnFGS397i X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::229 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Signed-off-by: Julien Grall Changes in v2: - Add missing ALIGN in xen.lds.S Acked-by: Ian Campbell --- xen/arch/arm/Makefile | 1 + xen/arch/arm/device.c | 74 ++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/xen.lds.S | 7 ++++ xen/include/asm-arm/device.h | 52 +++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 xen/arch/arm/device.c create mode 100644 xen/include/asm-arm/device.h diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 8f75044..4955a21 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -28,6 +28,7 @@ obj-y += vgic.o obj-y += vtimer.o obj-y += vpl011.o obj-y += hvm.o +obj-y += device.o #obj-bin-y += ....o diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c new file mode 100644 index 0000000..dc751a9 --- /dev/null +++ b/xen/arch/arm/device.c @@ -0,0 +1,74 @@ +/* + * xen/arch/arm/device.c + * + * Helpers to use a device retrieved via the device tree. + * + * Julien Grall + * Copyright (C) 2013 Linaro Limited. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +extern const struct device_desc _sdevice[], _edevice[]; + +static bool_t __init device_is_compatible(const struct device_desc *desc, + const struct dt_device_node *dev) +{ + const char *const *compat; + + if ( !desc->compatible ) + return 0; + + for ( compat = desc->compatible; *compat; compat++ ) + { + if ( dt_device_is_compatible(dev, *compat) ) + return 1; + } + + return 0; +} + +int __init device_init(struct dt_device_node *dev, enum device_type type, + const void *data) +{ + const struct device_desc *desc; + + ASSERT(dev != NULL); + + for ( desc = _sdevice; desc != _edevice; desc++ ) + { + if ( desc->type != type ) + continue; + + if ( device_is_compatible(desc, dev) ) + { + ASSERT(desc->init != NULL); + + return desc->init(dev, data); + } + + } + + return -EBADF; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index fd755d7..deab040 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -76,6 +76,13 @@ SECTIONS __lock_profile_end = .; #endif + . = ALIGN(8); + .dev.info : { + _sdevice = .; + *(.dev.info) + _edevice = .; + } :text + . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; .init.text : { diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h new file mode 100644 index 0000000..9e47ca6 --- /dev/null +++ b/xen/include/asm-arm/device.h @@ -0,0 +1,52 @@ +#ifndef __ASM_ARM_DEVICE_H +#define __ASM_ARM_DEVICE_H + +#include +#include + +enum device_type +{ + DEVICE_SERIAL +}; + +struct device_desc { + /* Device name */ + const char *name; + /* Device type */ + enum device_type type; + /* Array of device tree 'compatible' strings */ + const char *const *compatible; + /* Device initialization */ + int (*init)(struct dt_device_node *dev, const void *data); +}; + +/** + * device_init - Initialize a device + * @dev: device to initialize + * @type: type of the device (serial, network...) + * @data: specific data for initializing the device + * + * Return 0 on success. + */ +int __init device_init(struct dt_device_node *dev, enum device_type type, + const void *data); + +#define DT_DEVICE_START(_name, _namestr, _type) \ +static const struct device_desc __dev_desc_##_name __used \ +__attribute__((__section__(".dev.info"))) = { \ + .name = _namestr, \ + .type = _type, \ + +#define DT_DEVICE_END \ +}; + +#endif /* __ASM_ARM_DEVICE_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */