[{"id":1771562,"web_url":"http://patchwork.ozlabs.org/comment/1771562/","msgid":"<CAEUhbmWo+mdY7Z3E1PHL8248E9cSO+6rup3mK_yNUmV0jSjz=Q@mail.gmail.com>","list_archive_url":null,"date":"2017-09-20T05:01:40","subject":"Re: [U-Boot] [PATCH v2 1/6] pci: Add helper for implementing\n\tmemory-mapped config space accesses","submitter":{"id":64981,"url":"http://patchwork.ozlabs.org/api/people/64981/","name":"Bin Meng","email":"bmeng.cn@gmail.com"},"content":"Hi Tuomas,\n\nOn Wed, Sep 20, 2017 at 4:18 AM, Tuomas Tynkkynen\n<tuomas.tynkkynen@iki.fi> wrote:\n> This sort of pattern for implementing memory-mapped PCI config space\n> accesses appears in U-Boot twice already, and a third user is coming up.\n> So add helper functions to avoid code duplication, similar to how Linux\n> has pci_generic_config_write and pci_generic_config_read.\n>\n> Signed-off-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>\n> ---\n>  drivers/pci/pci-uclass.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++\n>  include/pci.h            | 51 ++++++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 109 insertions(+)\n>\n> diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c\n> index 86df141d60..5a24eb6428 100644\n> --- a/drivers/pci/pci-uclass.c\n> +++ b/drivers/pci/pci-uclass.c\n> @@ -518,6 +518,64 @@ int pci_auto_config_devices(struct udevice *bus)\n>         return sub_bus;\n>  }\n>\n> +int pci_generic_mmap_write_config(\n> +       struct udevice *bus,\n> +       int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp),\n> +       pci_dev_t bdf,\n> +       uint offset,\n> +       ulong value,\n> +       enum pci_size_t size)\n> +{\n> +       void *address;\n> +\n> +       if (addr_f(bus, bdf, offset, &address) < 0)\n> +               return 0;\n> +\n> +       switch (size) {\n> +       case PCI_SIZE_8:\n> +               writeb(value, address);\n> +               return 0;\n> +       case PCI_SIZE_16:\n> +               writew(value, address);\n> +               return 0;\n> +       case PCI_SIZE_32:\n> +               writel(value, address);\n> +               return 0;\n> +       default:\n> +               return -EINVAL;\n> +       }\n> +}\n> +\n> +int pci_generic_mmap_read_config(\n> +       struct udevice *bus,\n> +       int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp),\n> +       pci_dev_t bdf,\n> +       uint offset,\n> +       ulong *valuep,\n> +       enum pci_size_t size)\n> +{\n> +       void *address;\n> +\n> +       if (addr_f(bus, bdf, offset, &address) < 0) {\n> +               *valuep = pci_get_ff(size);\n> +               return 0;\n> +       }\n> +\n> +       switch (size) {\n> +       case PCI_SIZE_8:\n> +               *valuep = readb(address);\n> +               return 0;\n> +       case PCI_SIZE_16:\n> +               *valuep = readw(address);\n> +               return 0;\n> +       case PCI_SIZE_32:\n> +               *valuep = readl(address);\n> +               return 0;\n> +       default:\n> +               return -EINVAL;\n> +       }\n> +}\n> +\n>  int dm_pci_hose_probe_bus(struct udevice *bus)\n>  {\n>         int sub_bus;\n> diff --git a/include/pci.h b/include/pci.h\n> index c8ef997d0d..7adc04301c 100644\n> --- a/include/pci.h\n> +++ b/include/pci.h\n> @@ -1086,6 +1086,57 @@ int pci_read_config32(pci_dev_t pcidev, int offset, u32 *valuep);\n>  int pci_read_config16(pci_dev_t pcidev, int offset, u16 *valuep);\n>  int pci_read_config8(pci_dev_t pcidev, int offset, u8 *valuep);\n>\n> +/**\n> + * pci_generic_mmap_write_config() - Generic helper for writing to\n> + * memory-mapped PCI configuration space.\n\nnits: suggest adding one blank line here.\n\n> + * @bus: Pointer to the PCI bus\n> + * @addr_f: Callback for calculating the config space address\n> + * @bdf: Identifies the PCI device to access\n> + * @offset: The offset into the device's configuration space\n> + * @value: The value to write\n> + * @size: Indicates the size of access to perform\n> + *\n> + * Write the value @value of size @size from offset @offset within the\n> + * configuration space of the device identified by the bus, device & function\n> + * numbers in @bdf on the PCI bus @bus. The callback function @addr_f is\n> + * responsible for calculating the CPU address of the respective configuration\n> + * space offset.\n> + *\n> + * Return: 0 on success, else -EINVAL\n> + */\n> +int pci_generic_mmap_write_config(\n> +       struct udevice *bus,\n> +       int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp),\n> +       pci_dev_t bdf,\n> +       uint offset,\n> +       ulong value,\n> +       enum pci_size_t size);\n> +\n> +/**\n> + * pci_generic_mmap_read_config() - Generic helper for reading from\n> + * memory-mapped PCI configuration space.\n\nnits: suggest adding one blank line here.\n\n> + * @bus: Pointer to the PCI bus\n> + * @addr_f: Callback for calculating the config space address\n> + * @bdf: Identifies the PCI device to access\n> + * @offset: The offset into the device's configuration space\n> + * @valuep: A pointer at which to store the read value\n> + * @size: Indicates the size of access to perform\n> + *\n> + * Read a value of size @size from offset @offset within the configuration\n> + * space of the device identified by the bus, device & function numbers in @bdf\n> + * on the PCI bus @bus. The callback function @addr_f is responsible for\n> + * calculating the CPU address of the respective configuration space offset.\n> + *\n> + * Return: 0 on success, else -EINVAL\n> + */\n> +int pci_generic_mmap_read_config(\n> +       struct udevice *bus,\n> +       int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp),\n> +       pci_dev_t bdf,\n> +       uint offset,\n> +       ulong *valuep,\n> +       enum pci_size_t size);\n> +\n>  #ifdef CONFIG_DM_PCI_COMPAT\n>  /* Compatibility with old naming */\n>  static inline int pci_write_config_dword(pci_dev_t pcidev, int offset,\n> --\n\nOther than above nits:\n\nReviewed-by: Bin Meng <bmeng.cn@gmail.com>\n\nRegards,\nBin","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"GsiDLYti\"; dkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xxnfF0Hbfz9sBW\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 20 Sep 2017 15:01:55 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 1F9B9C21DCA; Wed, 20 Sep 2017 05:01:49 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 51783C21C50;\n\tWed, 20 Sep 2017 05:01:46 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 8F690C21C40; Wed, 20 Sep 2017 05:01:44 +0000 (UTC)","from mail-wm0-f65.google.com (mail-wm0-f65.google.com\n\t[74.125.82.65])\n\tby lists.denx.de (Postfix) with ESMTPS id 07CB3C21C35\n\tfor <u-boot@lists.denx.de>; Wed, 20 Sep 2017 05:01:41 +0000 (UTC)","by mail-wm0-f65.google.com with SMTP id x17so1313984wmd.5\n\tfor <u-boot@lists.denx.de>; Tue, 19 Sep 2017 22:01:41 -0700 (PDT)","by 10.223.145.3 with HTTP; Tue, 19 Sep 2017 22:01:40 -0700 (PDT)"],"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,\n\tRCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,\n\tT_DKIM_INVALID\n\tautolearn=unavailable autolearn_force=no version=3.4.0","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=mime-version:in-reply-to:references:from:date:message-id:subject:to\n\t:cc; bh=gk3dgEz8jTgVHLO+pynjJQNKPlcbxVSk29P3N1zKVeg=;\n\tb=GsiDLYti5viG4mHlgqv3n5O6KRmyAkWjKnHsUv7/wUkTXCKkpddCQ2FfEThcEe+jym\n\tVN6WFwS9C4U6EIrwofq0YBQcbKWKktnayj3E3vNNNo9KHKm4VAli9U6y9lMzqalA18V2\n\tB1XvKezOeJukUywhDDsagnWd6Lb3z+woOoT/C5BzkyGO24HtGqYjvqKRLU8NCvcoNPaY\n\tGkT0XMsKYgPHhcozV1j9gbj9SrMyJPMRE74eAXALGaHEwGhV2Qj4O7Tz/YDhSCAQzzM8\n\t67MGLNGlDtzYJ+bZeU7+Mb6lo7kMWgKCtrIk29J0lGp/BijX39q7OkpCCbLeAJECqk7w\n\tZFgA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:in-reply-to:references:from:date\n\t:message-id:subject:to:cc;\n\tbh=gk3dgEz8jTgVHLO+pynjJQNKPlcbxVSk29P3N1zKVeg=;\n\tb=lxFqwA0Wvym2nuLJ5l09dVVq7nkgXzzY47M04FM3hm6QFVxkdRkaLFbA4IgRk5q0se\n\tt7YioFgb0qnlB/IVrd7JSgdIB/K0tIDX5MIvP7dJv3WebDFXofDVBAYqTYSMqvwa0Ap+\n\txkdT53tAvZ4+u5PaOvsHu2L8ffEPKvqxjm2s5SD+o5kaNqboZF5EeLmG7lyLDSyqMrDp\n\t50D3pgmH0K0sA0hcRe4u5oZJ/yLzRyEA7+pamO/X0IZGRno58MEWLtljm+6aDQk1tD6u\n\typaDd/YI9FEp4GVCg+b3eD2gSyocgH+x7ZzuFVZ88Du4Qqh3jJuwEZQalVLvLYO+SRE6\n\thBlg==","X-Gm-Message-State":"AHPjjUiGe9GVTkCCEoQkWB8SAO5gi9Nrl/dGi1fhDQUhvQ0Qv+pkyhFK\n\t71Huj+CCE5kl5f3FwlrJqDWlg0EjjkDmY90dJpc=","X-Google-Smtp-Source":"AOwi7QDVKlMlbtQ/gUTZUPMNpreMnnEjJM8KgnA0aKdMvtcCCrg7/lAua6/UurQRx/L+MxDPI6Gy9vNxtFavOC9K8Ao=","X-Received":"by 10.28.218.141 with SMTP id r135mr3077412wmg.63.1505883700596; \n\tTue, 19 Sep 2017 22:01:40 -0700 (PDT)","MIME-Version":"1.0","In-Reply-To":"<20170919201808.11433-2-tuomas.tynkkynen@iki.fi>","References":"<20170919201808.11433-1-tuomas.tynkkynen@iki.fi>\n\t<20170919201808.11433-2-tuomas.tynkkynen@iki.fi>","From":"Bin Meng <bmeng.cn@gmail.com>","Date":"Wed, 20 Sep 2017 13:01:40 +0800","Message-ID":"<CAEUhbmWo+mdY7Z3E1PHL8248E9cSO+6rup3mK_yNUmV0jSjz=Q@mail.gmail.com>","To":"Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>","Cc":"U-Boot Mailing List <u-boot@lists.denx.de>, Tom Rini <trini@konsulko.com>","Subject":"Re: [U-Boot] [PATCH v2 1/6] pci: Add helper for implementing\n\tmemory-mapped config space accesses","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}},{"id":1782114,"web_url":"http://patchwork.ozlabs.org/comment/1782114/","msgid":"<20171007130745.GO25966@bill-the-cat>","list_archive_url":null,"date":"2017-10-07T13:07:45","subject":"Re: [U-Boot] [U-Boot, v2,\n\t1/6] pci: Add helper for implementing memory-mapped config space\n\taccesses","submitter":{"id":65875,"url":"http://patchwork.ozlabs.org/api/people/65875/","name":"Tom Rini","email":"trini@konsulko.com"},"content":"On Tue, Sep 19, 2017 at 11:18:03PM +0300, Tuomas Tynkkynen wrote:\n\n> This sort of pattern for implementing memory-mapped PCI config space\n> accesses appears in U-Boot twice already, and a third user is coming up.\n> So add helper functions to avoid code duplication, similar to how Linux\n> has pci_generic_config_write and pci_generic_config_read.\n> \n> Signed-off-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>\n> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>\n\nApplied to u-boot/master, thanks!","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=konsulko.com header.i=@konsulko.com\n\theader.b=\"M9U5RF89\"; dkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3y8Rpl2B1Yz9t6m\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSun,  8 Oct 2017 00:16:14 +1100 (AEDT)","by lists.denx.de (Postfix, from userid 105)\n\tid B18AFC21E79; Sat,  7 Oct 2017 13:10:41 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 29A9BC21E3D;\n\tSat,  7 Oct 2017 13:09:04 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 72BCAC21E3B; Sat,  7 Oct 2017 13:07:54 +0000 (UTC)","from mail-qt0-f181.google.com (mail-qt0-f181.google.com\n\t[209.85.216.181])\n\tby lists.denx.de (Postfix) with ESMTPS id 3F2D8C21DE5\n\tfor <u-boot@lists.denx.de>; Sat,  7 Oct 2017 13:07:49 +0000 (UTC)","by mail-qt0-f181.google.com with SMTP id f15so36017420qtf.7\n\tfor <u-boot@lists.denx.de>; Sat, 07 Oct 2017 06:07:49 -0700 (PDT)","from bill-the-cat ([2606:a000:1401:811b:6821:3a00:ff9f:889e])\n\tby smtp.gmail.com with ESMTPSA id\n\tg204sm3117132ywb.7.2017.10.07.06.07.47\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tSat, 07 Oct 2017 06:07:47 -0700 (PDT)"],"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=RCVD_IN_MSPIKE_H3,\n\tRCVD_IN_MSPIKE_WL,\n\tT_DKIM_INVALID autolearn=unavailable autolearn_force=no\n\tversion=3.4.0","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com;\n\ts=google; \n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:in-reply-to:user-agent;\n\tbh=NYSHQ+MGT2jHgSvE80uaFia6D+76C4c4ut8wS1KZWN8=;\n\tb=M9U5RF89fhMs+VA3RmSuOQ0hH9L68REHru2PJ7EvESlI7Oru4TXSfnALG3BbeDk+mn\n\tTDUk79Y9yyV6JAQodwW1RcllfAVGiHhQnUhoLiYg5YFb+ev98htL9ICRM8rZKDIRPpGR\n\t7sQiuYCJmXtmfera5VQsv46187snXxmsLxnpg=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:in-reply-to:user-agent;\n\tbh=NYSHQ+MGT2jHgSvE80uaFia6D+76C4c4ut8wS1KZWN8=;\n\tb=X+EJiaMqiy1OkKUfH9cmuW2U4be7yog3MEXjIqfQhXcs4DciSJ6DJIXIXerio6HYKV\n\tkgJgJ7ODLAcfJUvpYf7I/dE5NrOyC/oMDMyeC7FOAtTJgxgm/ZaK05cv/LJDRmxAzgDJ\n\t+fa6ftzatKGNsOAlYmrwtT+A1HJR/8AW01P4x5BkC55BGvGWVjvWD36PIJrJFZbhuCV3\n\t7TYohzS0Aw+m05UEgFsHQylMqk2c5DJavGDANTjJr9+N35Y8yyAPUOcqDxRrgPgrAaFf\n\t3dgS8u3Y7kdU7XLkI+djWbuANdA4X1KcPHw0hNSEYw/o9IN+ZdjJ0cDz5iDWKxlNr4TF\n\tduzg==","X-Gm-Message-State":"AMCzsaVh9LT5gm8ceI4wcv0NTrEX4H1zjmD8EcJHAVP7LMYcEqe6CO+5\n\tEoPZbZbTIzJuk0mHn8kfztrcfA==","X-Google-Smtp-Source":"AOwi7QCrdI6ikUfwMrGDHH2RZ50kPSC+Y4bA4PUcnxVT/4jMRziUf5dwiQSOXPRbDUL8ZISvvcQJVA==","X-Received":"by 10.13.243.133 with SMTP id c127mr4062657ywf.72.1507381668185; \n\tSat, 07 Oct 2017 06:07:48 -0700 (PDT)","Date":"Sat, 7 Oct 2017 09:07:45 -0400","From":"Tom Rini <trini@konsulko.com>","To":"Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>","Message-ID":"<20171007130745.GO25966@bill-the-cat>","References":"<20170919201808.11433-2-tuomas.tynkkynen@iki.fi>","MIME-Version":"1.0","In-Reply-To":"<20170919201808.11433-2-tuomas.tynkkynen@iki.fi>","User-Agent":"Mutt/1.5.24 (2015-08-30)","Cc":"u-boot@lists.denx.de","Subject":"Re: [U-Boot] [U-Boot, v2,\n\t1/6] pci: Add helper for implementing memory-mapped config space\n\taccesses","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Type":"multipart/mixed;\n\tboundary=\"===============6499645244410360065==\"","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}}]