From patchwork Wed Sep 25 14:56:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1167454 X-Patchwork-Delegate: bmeng.cn@gmail.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=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="OxvUSk7m"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46djff6Y6Qz9sNx for ; Thu, 26 Sep 2019 02:08:58 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 98057C22108; Wed, 25 Sep 2019 16:08:46 +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=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 9A8DEC221ED; Wed, 25 Sep 2019 15:04:01 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4606BC221D5; Wed, 25 Sep 2019 15:03:59 +0000 (UTC) Received: from mail-io1-f67.google.com (mail-io1-f67.google.com [209.85.166.67]) by lists.denx.de (Postfix) with ESMTPS id 66F81C220AF for ; Wed, 25 Sep 2019 14:58:57 +0000 (UTC) Received: by mail-io1-f67.google.com with SMTP id b136so14641254iof.3 for ; Wed, 25 Sep 2019 07:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7zVPGQSSkA6kk/zvGZ0yJ5xDOyOvPbaXb336puBoYJg=; b=OxvUSk7m0+oPNQgSwvDnOVJABNKwYweY8xM79LDppYv1qgSW9Si3IKzv7KqkEN4AvT r10M2BwCHLmz3Ntv7JmCDA+ADVfRYbpBp6MrCh/kQaEXSG05svtEu/SNxqEkhytnK0RO 4QoyJ4gT/teuDOHoZynqXXS6eQQcckt+f26gM= 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=7zVPGQSSkA6kk/zvGZ0yJ5xDOyOvPbaXb336puBoYJg=; b=G00wYareuN8+ZVjiaQl0CEOsjckaxdrcPESLFcwTnW5RXfDN25ibnkfW3oLZz3MnqW kEPtEBj+18+eLCkHT9c6qr2JEbetHJ3YaZBhy9741JTMYpsqntq24udRy/BHRyLi+ypi 6KyMAhu1KzmW/ZOy10GMxvY0Gn63YydXj93aXbmXo146yYYzA5r2/jzFHTd8yx0gcGHp pvQppOgpKj0hF65beW1tczX7K9b/Bw8dZd8xfrHet4YWqHRppxhke6s9SnbBNcuErlnu QbY12l/lGy6IlUiLK7iLJ7m6hJB82S7aPcI/sjOUJ2C4eN41JKDkXUbs2NtLE76vohsP XSGw== X-Gm-Message-State: APjAAAU2nNBcQylRl84Owugx1i9CCAcxYQKK6i1F3KrGolOknEqLOHFt qIAV2aTazxUmscsrqVdNLLBRQXWZijU= X-Google-Smtp-Source: APXvYqyKW0hPpDxZL6DqfiVOBUXI8nMUagVNyCRcjW/lxXQvxz4ghLLMiRcr39eS09oF/4+eMgyW+w== X-Received: by 2002:a02:cc21:: with SMTP id o1mr5784279jap.116.1569423536178; Wed, 25 Sep 2019 07:58:56 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id d9sm4254964ioq.9.2019.09.25.07.58.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2019 07:58:55 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Wed, 25 Sep 2019 08:56:53 -0600 Message-Id: <20190925145750.200592-70-sjg@chromium.org> X-Mailer: git-send-email 2.23.0.444.g18eeb5a265-goog In-Reply-To: <20190925145750.200592-1-sjg@chromium.org> References: <20190925145750.200592-1-sjg@chromium.org> MIME-Version: 1.0 Subject: [U-Boot] [PATCH 069/126] sandbox: pci: Remember the device being emulated 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" Add a field to the PCI emulator per-device data which records which device is being emulated. This is useful when the emulator needs to check the device for something. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- drivers/pci/pci-emul-uclass.c | 32 +++++++++++++++++++++++++------- include/pci.h | 20 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/drivers/pci/pci-emul-uclass.c b/drivers/pci/pci-emul-uclass.c index 6e6172836a4..589fb539031 100644 --- a/drivers/pci/pci-emul-uclass.c +++ b/drivers/pci/pci-emul-uclass.c @@ -18,6 +18,7 @@ struct sandbox_pci_emul_priv { int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn, struct udevice **containerp, struct udevice **emulp) { + struct pci_emul_uc_priv *upriv; struct udevice *dev; int ret; @@ -30,17 +31,33 @@ int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn, } *containerp = dev; - /* - * TODO(sjg@chromium.org): This code needs a comment as I'm not sure - * why UCLASS_PCI_GENERIC devices end up being their own emulators. I - * left this code as is. - */ ret = uclass_get_device_by_phandle(UCLASS_PCI_EMUL, dev, "sandbox,emul", emulp); - if (ret && device_get_uclass_id(dev) != UCLASS_PCI_GENERIC) + if (!ret) { + upriv = dev_get_uclass_priv(*emulp); + + upriv->client = dev; + } else if (device_get_uclass_id(dev) != UCLASS_PCI_GENERIC) { + /* + * TODO(sjg@chromium.org): This code needs a comment as I'm not + * sure why non-UCLASS_PCI_GENERIC devices end up being their + * own emulators. I left this code as is. + */ *emulp = dev; + } + + return 0; +} - return *emulp ? 0 : -ENODEV; +int sandbox_pci_get_client(struct udevice *emul, struct udevice **devp) +{ + struct pci_emul_uc_priv *upriv = dev_get_uclass_priv(emul); + + if (!upriv->client) + return -ENOENT; + *devp = upriv->client; + + return 0; } uint sandbox_pci_read_bar(u32 barval, int type, uint size) @@ -89,6 +106,7 @@ UCLASS_DRIVER(pci_emul) = { .post_probe = sandbox_pci_emul_post_probe, .pre_remove = sandbox_pci_emul_pre_remove, .priv_auto_alloc_size = sizeof(struct sandbox_pci_emul_priv), + .per_device_auto_alloc_size = sizeof(struct pci_emul_uc_priv), }; /* diff --git a/include/pci.h b/include/pci.h index 8aa6636cfbf..ff59ac0e695 100644 --- a/include/pci.h +++ b/include/pci.h @@ -1490,6 +1490,17 @@ int dm_pci_find_device(unsigned int vendor, unsigned int device, int index, */ int dm_pci_find_class(uint find_class, int index, struct udevice **devp); +/** + * struct pci_emul_uc_priv - holds info about an emulator device + * + * There is always at most one emulator per client + * + * @client: Client device if any, else NULL + */ +struct pci_emul_uc_priv { + struct udevice *client; +}; + /** * struct dm_pci_emul_ops - PCI device emulator operations */ @@ -1592,6 +1603,15 @@ struct dm_pci_emul_ops { int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn, struct udevice **containerp, struct udevice **emulp); +/** + * sandbox_pci_get_client() - Find the client for an emulation device + * + * @emul: Emulation device to check + * @devp: Returns the client device emulated by this device + * @return 0 if OK, -ENOENT if the device has no client yet + */ +int sandbox_pci_get_client(struct udevice *emul, struct udevice **devp); + /** * pci_get_devfn() - Extract the devfn from fdt_pci_addr of the device *