From patchwork Fri May 10 02:18:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 16839 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A9F47238F7 for ; Fri, 10 May 2013 02:20:07 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id lx15sf843487lab.6 for ; Thu, 09 May 2013 19:19:42 -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=rHimGAhacNQL0szcOA1HpxxiGhyAaUZypzCsmpshzDk=; b=fzzXrJxUtxrl4DkcH6VxEDLhhl5yPVq20bvsB6YkJnoNg8iWhjDKe6rc84hYKwyHzX qmFRq/bg/Dl3Z1H//KbJkQeGadJkl5fKPlTQK2ffO/e+MRqxAU84cdK/rITGYalk62ZM YocrCh/+d6iVz2J7GwCeE6ONvPHmVjFqyyYcmGyJY5rjpaI7aAe2fWR95bg73HzjnvTk /xb6Nu1b55fKjP0EmyTBS8Ol+b+lHx1y91bxzJNW9QMRec4htyNG7WhzRnuYKWdsxJ25 hRdAtv9QEcvRK18Ec2eGfRNjE11zT+pjrbKbBPCrWg2eql2RXH9Ypv9f76xPeD8KjPB+ EUwA== X-Received: by 10.180.93.42 with SMTP id cr10mr121600wib.0.1368152382099; Thu, 09 May 2013 19:19:42 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.180.97.167 with SMTP id eb7ls29504wib.7.gmail; Thu, 09 May 2013 19:19:42 -0700 (PDT) X-Received: by 10.194.76.199 with SMTP id m7mr21489993wjw.43.1368152382021; Thu, 09 May 2013 19:19:42 -0700 (PDT) Received: from mail-ve0-x236.google.com (mail-ve0-x236.google.com [2607:f8b0:400c:c01::236]) by mx.google.com with ESMTPS id u10si148510wjx.253.2013.05.09.19.19.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 May 2013 19:19:42 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::236 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:c01::236; Received: by mail-ve0-f182.google.com with SMTP id da11so2043486veb.27 for ; Thu, 09 May 2013 19:19:40 -0700 (PDT) X-Received: by 10.220.89.198 with SMTP id f6mr9923674vcm.45.1368152380725; Thu, 09 May 2013 19:19:40 -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.220.217.15 with SMTP id hk15csp36233vcb; Thu, 9 May 2013 19:19:40 -0700 (PDT) X-Received: by 10.181.12.14 with SMTP id em14mr717065wid.18.1368152379456; Thu, 09 May 2013 19:19:39 -0700 (PDT) Received: from mail-wi0-x236.google.com (mail-wi0-x236.google.com [2a00:1450:400c:c05::236]) by mx.google.com with ESMTPS id y12si174306wiv.82.2013.05.09.19.19.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 May 2013 19:19:39 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c05::236 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=2a00:1450:400c:c05::236; Received: by mail-wi0-f182.google.com with SMTP id m6so153462wiv.15 for ; Thu, 09 May 2013 19:19:38 -0700 (PDT) X-Received: by 10.180.149.200 with SMTP id uc8mr760822wib.3.1368152378781; Thu, 09 May 2013 19:19:38 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id dj7sm597075wib.6.2013.05.09.19.19.37 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 May 2013 19:19:38 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: Stefano.Stabellini@eu.citrix.com, ian.campbell@citrix.com, patches@linaro.org, Julien Grall Subject: [PATCH V3 26/41] xen/arm: Introduce a generic way to use a device from the device tree Date: Fri, 10 May 2013 03:18:12 +0100 Message-Id: <1368152307-598-27-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1368152307-598-1-git-send-email-julien.grall@linaro.org> References: <1368152307-598-1-git-send-email-julien.grall@linaro.org> X-Gm-Message-State: ALoCoQnBp2R8O4N0C9v/JY+9YeXn9dWIo3gx2htjmvj7ZRe5SLKCkK+ggLpMtbn1bIRgthUZMgZe X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::236 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 Acked-by: Ian Campbell Changes in v2: - Add missing ALIGN in xen.lds.S --- 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: + */