From patchwork Thu Nov 29 19:57:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?= X-Patchwork-Id: 1005623 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Y34p8MJj"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 435SxM6m7jz9s9J for ; Fri, 30 Nov 2018 06:57:58 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id E30BFC22473; Thu, 29 Nov 2018 19:57:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 34931C22454; Thu, 29 Nov 2018 19:57:50 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AFC6EC22454; Thu, 29 Nov 2018 19:57:48 +0000 (UTC) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by lists.denx.de (Postfix) with ESMTPS id 5BA11C21F7E for ; Thu, 29 Nov 2018 19:57:48 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id s14so3565341wmh.1 for ; Thu, 29 Nov 2018 11:57:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=U+j7vU7pK2zryUAa+2/l4DqzOKPUQkvzW8mT1lHGeqE=; b=Y34p8MJj6dlEK6CKiVEpLsGSJQprtohNblabPFTgbzwxuHcnuXbD4XACxT54sv+Xo1 gh1FB1+3GQlA5JOWi2o4uMlw9tq45lpQPh4CWILzYpn5O9lHAe8Jlue/pRHYtuWIFpCG XrUgH2+XtdpKz1kFhTWv0DOXqBMfeJ/oGc5ATIZ7X03yaSKK/VdvSPL0HwFHhZb1Oc1V THBzDTxWxwD6FVU6+avXjU+HukCmWuRsdR0/4pS5yCsxfMgsDAQVb9jpfE0RbbXG4ya3 tngAI3WVII08m3AoMoTSN09SM4qZPKwLxFUJv6JZx6qchA2v8DeNuVNFwWE/seF7Enf+ ojwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=U+j7vU7pK2zryUAa+2/l4DqzOKPUQkvzW8mT1lHGeqE=; b=T1FjW612A04rBlz8KwyVKuZ+8P50P8Dncyr/2yP2MESx5WhOYt0SwNmWfm4k+Buvo+ Iw4ujEogSbWBRO2A5ytR5Teyh2fSCxHWqPtCcg2NQ+5YpdlYZ6LV3fbABwH4Np7G6DVN NKQf35DT0CvuQ07AOP5O67EPxQnVgjzWHTmIED9hhrm7ba4VqMeeIng0pqNIuF1AMVEG sVY9890q/zoNfVVW8jWW0cvJ9h/SZhnS7AH8n0iam1WUbUVvXRMVToOwpAgsxkFO6jfQ 4oy3+GwFimSyPiybWPNOI7uQWSNLWK/h7TP+3SVxeJ4fT/KMmQ3i2L14rMiZ6l+HBiA/ mEHA== X-Gm-Message-State: AA+aEWa/3scqA+c9NSBwEY7ychYpXZYfn48P32E6fafOWpZLNkR7jde8 Hva38+VqYIWh4jvO/ipd0Teuh+X+ X-Google-Smtp-Source: AFSGD/X9791/KUdC8W2OKXtNyy4BGTOfUcb8PSjHvTUVktwR9vF6bLBi99I3uxV8mO9gRT/eE4MbPA== X-Received: by 2002:a1c:4c10:: with SMTP id z16mr3100788wmf.117.1543521467623; Thu, 29 Nov 2018 11:57:47 -0800 (PST) Received: from skynet.lan (8.red-88-1-21.dynamicip.rima-tde.net. [88.1.21.8]) by smtp.gmail.com with ESMTPSA id j14sm1685887wrv.96.2018.11.29.11.57.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 11:57:47 -0800 (PST) From: =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?= To: u-boot@lists.denx.de, sjg@chromium.org, trini@konsulko.com, daniel.schwierzeck@gmail.com Date: Thu, 29 Nov 2018 20:57:45 +0100 Message-Id: <20181129195745.20615-1-noltari@gmail.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [U-Boot] [PATCH 1/1] dm: core: add functions to get/remap I/O addresses by name X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Signed-off-by: Álvaro Fernández Rojas --- drivers/core/fdtaddr.c | 10 ++++++++++ drivers/core/read.c | 20 ++++++++++++++++++++ include/dm/fdtaddr.h | 13 +++++++++++++ include/dm/read.h | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c index bfd9580050..e113f1dd39 100644 --- a/drivers/core/fdtaddr.c +++ b/drivers/core/fdtaddr.c @@ -146,6 +146,16 @@ void *devfdt_remap_addr_index(struct udevice *dev, int index) return map_physmem(addr, 0, MAP_NOCACHE); } +void *devfdt_remap_addr_name(struct udevice *dev, const char *name) +{ + fdt_addr_t addr = devfdt_get_addr_name(dev, name); + + if (addr == FDT_ADDR_T_NONE) + return NULL; + + return map_physmem(addr, 0, MAP_NOCACHE); +} + void *devfdt_remap_addr(struct udevice *dev) { return devfdt_remap_addr_index(dev, 0); diff --git a/drivers/core/read.c b/drivers/core/read.c index 96766c7876..cdd78be03e 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -69,6 +69,26 @@ void *dev_remap_addr_index(struct udevice *dev, int index) return map_physmem(addr, 0, MAP_NOCACHE); } +fdt_addr_t dev_read_addr_name(struct udevice *dev, const char *name) +{ + int index = dev_read_stringlist_search(dev, "reg-names", name); + + if (index < 0) + return FDT_ADDR_T_NONE; + else + return dev_read_addr_index(dev, index); +} + +void *dev_remap_addr_name(struct udevice *dev, const char *name) +{ + fdt_addr_t addr = dev_read_addr_name(dev, name); + + if (addr == FDT_ADDR_T_NONE) + return NULL; + + return map_physmem(addr, 0, MAP_NOCACHE); +} + fdt_addr_t dev_read_addr(struct udevice *dev) { return dev_read_addr_index(dev, 0); diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h index 49a6ffd5f8..c171d9bc2f 100644 --- a/include/dm/fdtaddr.h +++ b/include/dm/fdtaddr.h @@ -56,6 +56,19 @@ void *devfdt_remap_addr(struct udevice *dev); void *devfdt_remap_addr_index(struct udevice *dev, int index); /** + * devfdt_remap_addr_name() - Get the reg property of a device, indexed by + * name, as a memory-mapped I/O pointer + * @name: the 'reg' property can hold a list of pairs, with the + * 'reg-names' property providing named-based identification. @index + * indicates the value to search for in 'reg-names'. + * + * @dev: Pointer to a device + * + * @return Pointer to addr, or NULL if there is no such property + */ +void *devfdt_remap_addr_name(struct udevice *dev, const char *name); + +/** * devfdt_map_physmem() - Read device address from reg property of the * device node and map the address into CPU address * space. diff --git a/include/dm/read.h b/include/dm/read.h index a27b8554fb..efcbee15ec 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -125,6 +125,31 @@ fdt_addr_t dev_read_addr_index(struct udevice *dev, int index); void *dev_remap_addr_index(struct udevice *dev, int index); /** + * dev_read_addr_name() - Get the reg property of a device, indexed by name + * + * @dev: Device to read from + * @name: the 'reg' property can hold a list of pairs, with the + * 'reg-names' property providing named-based identification. @index + * indicates the value to search for in 'reg-names'. + * + * @return address or FDT_ADDR_T_NONE if not found + */ +fdt_addr_t dev_read_addr_name(struct udevice *dev, const char* name); + +/** + * dev_remap_addr_name() - Get the reg property of a device, indexed by name, + * as a memory-mapped I/O pointer + * + * @dev: Device to read from + * @name: the 'reg' property can hold a list of pairs, with the + * 'reg-names' property providing named-based identification. @index + * indicates the value to search for in 'reg-names'. + * + * @return pointer or NULL if not found + */ +void *dev_remap_addr_name(struct udevice *dev, const char* name); + +/** * dev_read_addr() - Get the reg property of a device * * @dev: Device to read from @@ -494,6 +519,12 @@ static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) return devfdt_get_addr_index(dev, index); } +static inline fdt_addr_t dev_read_addr_name(struct udevice *dev, + const char *name) +{ + return devfdt_get_addr_name(dev, name); +} + static inline fdt_addr_t dev_read_addr(struct udevice *dev) { return devfdt_get_addr(dev); @@ -514,6 +545,11 @@ static inline void *dev_remap_addr_index(struct udevice *dev, int index) return devfdt_remap_addr_index(dev, index); } +static inline void *dev_remap_addr_name(struct udevice *dev, const char *name) +{ + return devfdt_remap_addr_name(dev, name); +} + static inline fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname, fdt_size_t *sizep)