From patchwork Wed Apr 24 18:53:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramon Fried X-Patchwork-Id: 1090559 X-Patchwork-Delegate: trini@ti.com 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="Mv7bdHQP"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44qH0B1f8Sz9s3Z for ; Thu, 25 Apr 2019 09:41:46 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B82C4C21E1A; Wed, 24 Apr 2019 23:40:45 +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 12B9FC21DEC; Wed, 24 Apr 2019 23:40:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7E588C21DB3; Wed, 24 Apr 2019 18:54:04 +0000 (UTC) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by lists.denx.de (Postfix) with ESMTPS id BAC9AC21DB3 for ; Wed, 24 Apr 2019 18:54:03 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id c5so17723399wrs.11 for ; Wed, 24 Apr 2019 11:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SguxhCTSnpGomGWaCTWnsZpVweJCDixCYnCbj6pYR8c=; b=Mv7bdHQPqIMurOUGdHbU1tog9XJ6+KF9zpEGhlSyVGFDmw/IafTBfB4snDySMOPCMR MsWUgC4hcVlmDj8qqCY9aghHnoYLydP9fC3uw4/6aPpw37z6NK/gonoqyn3eZEWjdShy kU49er+tR7jku1ZYdiUYChwnBPdVTqJqbP24vneYXYHYJOgj/Yt2keTJQSCFhZRgK2Kb ATrQR7Fan/3nTz6JOrBmSAXrl7YfaFdUMrOI8xJA7b7bnfiCIf2XcY4D3ou5K7OhjhsN WQvGW13xR9/tDdYc+m/ED3pAA8nhGCN7mp8jT5Zz7IWkikjYbD9/FIxzpkyeZBwik/fa F1ug== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=SguxhCTSnpGomGWaCTWnsZpVweJCDixCYnCbj6pYR8c=; b=M0Tj5jwneZ8tGEjoMMtulJVi9mb60mPACiXXFOzcKBYFGml60jZdKbD2zW4B/CKQ04 oM6hHHFpsO8sQiwT00ufQfbdEx6lByu3Hhwd5jRl2pDrACkKhjvOsn8IFn8fXgnsGXtk wd/UQrGAexdi7viiwWOo2/Cd+iXEWO/zAbQb3OGpjR3+X186fDzsblbtSlEdMYE3+meZ GPTY2Lj5a19llPWcAZQIBd4HKkeZcTF+7lwJlU9VyDBg63EOxo8RYBSb0yzZ66WFYNGv zsuU7JcKUNu3mx4Na4tjzUPWh+RROL71NzdXVjq3pTsnCD07ZigFSZMJw5EYLiAzdCfX Ettg== X-Gm-Message-State: APjAAAX1/7pneYh5shXeL1AaPImM7JJyleWKTUYkbMZxWyaeRv2s/UT8 BB5e3izFQKzOHuP72ej5LG8= X-Google-Smtp-Source: APXvYqyfiPLwrhNFYVU8n2RfckvgxHFNARukfuAwIcUyBRbpxIkBE9iBG2EyCCTNqAjYj+OxUM7S9A== X-Received: by 2002:a5d:4a83:: with SMTP id o3mr5569263wrq.90.1556132043288; Wed, 24 Apr 2019 11:54:03 -0700 (PDT) Received: from localhost.localdomain ([141.226.31.91]) by smtp.gmail.com with ESMTPSA id z15sm11911868wrv.80.2019.04.24.11.54.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 11:54:02 -0700 (PDT) From: Ramon Fried To: sjg@chromium.org Date: Wed, 24 Apr 2019 21:53:46 +0300 Message-Id: <20190424185347.13586-4-ramon.fried@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424185347.13586-1-ramon.fried@gmail.com> References: <20190424185347.13586-1-ramon.fried@gmail.com> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 24 Apr 2019 23:39:57 +0000 Cc: Ramon Fried , Eugeniu Rosca , u-boot@lists.denx.de, Joe Hershberger Subject: [U-Boot] [PATCH v2 3/4] pci_ep: add pci_ep sandbox driver 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: Ramon Fried --- arch/sandbox/dts/test.dts | 4 + configs/sandbox64_defconfig | 2 + configs/sandbox_defconfig | 2 + drivers/pci_endpoint/Kconfig | 7 + drivers/pci_endpoint/Makefile | 1 + drivers/pci_endpoint/sandbox-pci_ep.c | 176 ++++++++++++++++++++++++++ 6 files changed, 192 insertions(+) create mode 100644 drivers/pci_endpoint/sandbox-pci_ep.c diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 8b2d6451c6..001dc302ed 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -475,6 +475,10 @@ }; }; + pci_ep: pci_ep { + compatible = "sandbox,pci_ep"; + }; + probing { compatible = "simple-bus"; test1 { diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index c04ecd915a..7137ea481c 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -127,9 +127,11 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_DM_ETH=y CONFIG_NVME=y CONFIG_PCI=y +CONFIG_PCI_ENDPOINT=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_PCI_SANDBOX_EP=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index bb508a8d02..04ba9a3ba1 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -142,9 +142,11 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_DM_ETH=y CONFIG_NVME=y CONFIG_PCI=y +CONFIG_PCI_ENDPOINT=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_PCI_SANDBOX_EP=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=y diff --git a/drivers/pci_endpoint/Kconfig b/drivers/pci_endpoint/Kconfig index c54bd2a9ac..e529e560fc 100644 --- a/drivers/pci_endpoint/Kconfig +++ b/drivers/pci_endpoint/Kconfig @@ -22,4 +22,11 @@ config PCIE_CADENCE_EP endpoint mode. This PCIe controller may be embedded into many different vendors SoCs. +config PCI_SANDBOX_EP + bool "Sandbox PCIe endpoint controller" + depends on PCI_ENDPOINT + help + Say Y here if you want to support the Sandbox PCIe controller in + endpoint mode. + endmenu diff --git a/drivers/pci_endpoint/Makefile b/drivers/pci_endpoint/Makefile index 0a849deb19..3cd987259d 100644 --- a/drivers/pci_endpoint/Makefile +++ b/drivers/pci_endpoint/Makefile @@ -5,3 +5,4 @@ obj-y += pci_ep-uclass.o obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep.o +obj-$(CONFIG_PCI_SANDBOX_EP) += sandbox-pci_ep.o diff --git a/drivers/pci_endpoint/sandbox-pci_ep.c b/drivers/pci_endpoint/sandbox-pci_ep.c new file mode 100644 index 0000000000..eb19c6da81 --- /dev/null +++ b/drivers/pci_endpoint/sandbox-pci_ep.c @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2019 Ramon Fried + */ + +#include +#include +#include +#include +#include +#include + +struct sandbox_pci_ep_priv { + struct pci_ep_header hdr; + int msix; + int msi; +}; + +static const struct udevice_id sandbox_pci_ep_ids[] = { + { .compatible = "sandbox,pci_ep" }, + { } +}; + +static int sandbox_write_header(struct udevice *dev, uint fn, + struct pci_ep_header *hdr) +{ + struct sandbox_pci_ep_priv *priv = dev_get_priv(dev); + + if (fn > 0) + return -ENODEV; + + memcpy(&priv->hdr, hdr, sizeof(*hdr)); + + return 0; +} + +static int sandbox_read_header(struct udevice *dev, uint fn, + struct pci_ep_header *hdr) +{ + struct sandbox_pci_ep_priv *priv = dev_get_priv(dev); + + if (fn > 0) + return -ENODEV; + + memcpy(hdr, &priv->hdr, sizeof(*hdr)); + + return 0; +} + +static int sandbox_set_bar(struct udevice *dev, uint fn, + struct pci_bar *ep_bar) +{ + if (fn > 0) + return -ENODEV; + return 0; +} + +int sandbox_clear_bar(struct udevice *dev, uint fn, + enum pci_barno bar) +{ + if (fn > 0) + return -ENODEV; + return 0; +} + +static int sandbox_map_addr(struct udevice *dev, uint fn, phys_addr_t addr, + u64 pci_addr, size_t size) +{ + if (fn > 0) + return -ENODEV; + + return 0; +} + +static void sandbox_unmap_addr(struct udevice *dev, uint fn, phys_addr_t addr) +{ + if (fn > 0) + return; +} + +static int sandbox_set_msi(struct udevice *dev, uint fn, uint interrupts) +{ + struct sandbox_pci_ep_priv *priv = dev_get_priv(dev); + + if (fn > 0) + return -ENODEV; + + priv->msi = interrupts; + + return 0; +} + +static int sandbox_get_msi(struct udevice *dev, uint fn) +{ + struct sandbox_pci_ep_priv *priv = dev_get_priv(dev); + + if (fn > 0) + return -ENODEV; + + return priv->msi; +} + +static int sandbox_set_msix(struct udevice *dev, uint fn, uint interrupts) +{ + struct sandbox_pci_ep_priv *priv = dev_get_priv(dev); + + if (fn > 0) + return -ENODEV; + + priv->msix = interrupts; + + return 0; +} + +static int sandbox_get_msix(struct udevice *dev, uint fn) +{ + struct sandbox_pci_ep_priv *priv = dev_get_priv(dev); + + if (fn > 0) + return -ENODEV; + + return priv->msix; +} + +static int sandbox_raise_irq(struct udevice *dev, uint fn, + enum pci_ep_irq_type type, uint interrupt_num) +{ + if (fn > 0) + return -ENODEV; + + return 0; +} + +static int sandbox_start(struct udevice *dev) +{ + return 0; +} + +static int sandbox_stop(struct udevice *dev) +{ + return 0; +} + +static int sandbox_pci_ep_probe(struct udevice *dev) +{ + struct sandbox_pci_ep_priv *priv = dev_get_priv(dev); + + memset(priv, 0, sizeof(*priv)); + + return 0; +} + +static struct pci_ep_ops sandbox_pci_ep_ops = { + .write_header = sandbox_write_header, + .read_header = sandbox_read_header, + .set_bar = sandbox_set_bar, + .clear_bar = sandbox_clear_bar, + .map_addr = sandbox_map_addr, + .unmap_addr = sandbox_unmap_addr, + .set_msi = sandbox_set_msi, + .get_msi = sandbox_get_msi, + .set_msix = sandbox_set_msix, + .get_msix = sandbox_get_msix, + .raise_irq = sandbox_raise_irq, + .start = sandbox_start, + .stop = sandbox_stop, +}; + +U_BOOT_DRIVER(pci_ep_sandbox) = { + .name = "pci_ep_sandbox", + .id = UCLASS_PCI_EP, + .of_match = sandbox_pci_ep_ids, + .probe = sandbox_pci_ep_probe, + .ops = &sandbox_pci_ep_ops, + .priv_auto_alloc_size = sizeof(struct sandbox_pci_ep_priv), +};