From patchwork Thu Sep 4 13:04:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 218 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756991130; bh=bHrfOralAswRraLXXOB5hvEemJnvl/AOifCZ14ORUxs=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=aDECA0oiiE7H+Xw5bHgmjDbKdy2y+LXeWlg1NqoE0tOE/9ydCQKEy9P+jDHcOBd55 ldHKwOH3zLFtULCKAJB/qMUVc7IpKWdYovGAGjP34l156AMWcj9bcoanrbVDvJLCUK pdEoKJkVDQZ+yRTPSSeFR+2qhBruICLLAcJ4jz9hnMhn9ZnlEIxb1EFB7iKGTpMY6l YuT3UVyuQbl7u1BCdB/ORfukKV20AFJZT9AAtz82vFcXQdbEXkBEeWSLyojU0RZsK7 x4cGwvZbwMsRMwW2HBmnHvK6XrnHQEuIfxbJa4nFYPE+o9u2lpOiIi4Yvu1p3Qkb+k e55WbTzBmINYg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DB3986795D for ; Thu, 4 Sep 2025 07:05:30 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id XCJAMoZxH1rl for ; Thu, 4 Sep 2025 07:05:30 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756991130; bh=bHrfOralAswRraLXXOB5hvEemJnvl/AOifCZ14ORUxs=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=aDECA0oiiE7H+Xw5bHgmjDbKdy2y+LXeWlg1NqoE0tOE/9ydCQKEy9P+jDHcOBd55 ldHKwOH3zLFtULCKAJB/qMUVc7IpKWdYovGAGjP34l156AMWcj9bcoanrbVDvJLCUK pdEoKJkVDQZ+yRTPSSeFR+2qhBruICLLAcJ4jz9hnMhn9ZnlEIxb1EFB7iKGTpMY6l YuT3UVyuQbl7u1BCdB/ORfukKV20AFJZT9AAtz82vFcXQdbEXkBEeWSLyojU0RZsK7 x4cGwvZbwMsRMwW2HBmnHvK6XrnHQEuIfxbJa4nFYPE+o9u2lpOiIi4Yvu1p3Qkb+k e55WbTzBmINYg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BDCDD6794A for ; Thu, 4 Sep 2025 07:05:30 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756991128; bh=E70+o6o0XDysoCP4VZ7+aGy7KkMdAIPQJgSLt+ettC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=paNJEXJCIGRfGy7rjMoAaRn69eRjcpqt8JHbIHrbmxaTpfY1qcbz07ZW6qjDf5kPj oOTu5ap+oPlA+otrOd/HIoq+SDhTjIVT1npI58crLzSI+T8x5H0vF5GvfUlbaK8v+3 tCYXaEebOSNDY9RKMW6FX55L+pJQsFr7EjZDfTB2eF4ITkLXfJ3T6LgjMb5mRQ8+Y3 FBofu5ldMY6ZLtwgVRbJFaxhJOS0tUENwQlI63pAX/uf7OjpZbVoNQ8sdN0ekXh6Ra 1eI2QSbtKR4ID4bD+jDzbUF1boK2gfE2iEoz9uAdtdY4PmJecjqyuUgheq5nm3Yugz em25zn+SKtZNw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EE9236795E; Thu, 4 Sep 2025 07:05:28 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id zKpgEZKzxdR2; Thu, 4 Sep 2025 07:05:28 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756991123; bh=bHPVgjpzKCvriybOo9Dy1Dy/lZ5/v7gAX+1/dc2NLzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EPVd8ykQV0MkxvqK4V0qtXc6Z4rOZbRf+DZN/rGJAhfj/SnNMDEMK9iUnPN1RyMRu fo3hP0X9kTITe9kfxLHfKTIGMuIfy/Uqj8ukXeDDr6kEthvG9DefnyDmQho+sqXT72 y9lHDKHZ1orvdKTpMjvkHj89F3bTl3W3eBejaWLnVe6nw2ELybvmy+xNINxvPutG0G U9tDE+TBNhsQ1EeqGBIrSyowz0BeShYKcQnAK64vTPLzzCodIW0Kdy3y1jL3x+groI FYFTMV3D7en9Pj0mnATMVn9jUhHb6W5hwycIgwhSChSwfmmNdTSN+nVAnV23mQEORK lq9mwz1eJdMnA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 097D56794A; Thu, 4 Sep 2025 07:05:22 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 4 Sep 2025 07:04:37 -0600 Message-ID: <20250904130459.848794-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250904130459.848794-1-sjg@u-boot.org> References: <20250904130459.848794-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: JWZJMIXKZRU4ZZQJUU63RA4L5BIMIUCV X-Message-ID-Hash: JWZJMIXKZRU4ZZQJUU63RA4L5BIMIUCV X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 04/18] sandbox: Move PCI functions to separate header file List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Move pci_map_physmem(), pci_unmap_physmem(), and sandbox_set_enable_pci_map() from u-boot-sandbox.h to a new file sandbox_pci.h to simplify dependencies. Fix the header order in the PCI emul file while we are here. Co-developed-by: Claude Signed-off-by: Simon Glass --- arch/sandbox/cpu/mem.c | 1 + arch/sandbox/include/asm/sandbox_pci.h | 61 +++++++++++++++++++++++ arch/sandbox/include/asm/u-boot-sandbox.h | 50 +------------------ drivers/pci/pci-emul-uclass.c | 3 +- test/dm/pci.c | 1 + 5 files changed, 67 insertions(+), 49 deletions(-) create mode 100644 arch/sandbox/include/asm/sandbox_pci.h diff --git a/arch/sandbox/cpu/mem.c b/arch/sandbox/cpu/mem.c index 4e9b629e3aa..b5c7ea6493d 100644 --- a/arch/sandbox/cpu/mem.c +++ b/arch/sandbox/cpu/mem.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include diff --git a/arch/sandbox/include/asm/sandbox_pci.h b/arch/sandbox/include/asm/sandbox_pci.h new file mode 100644 index 00000000000..a4a4eaece8f --- /dev/null +++ b/arch/sandbox/include/asm/sandbox_pci.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#ifndef _ASM_SANDBOX_PCI_H_ +#define _ASM_SANDBOX_PCI_H_ + +#include + +struct udevice; + +/** + * pci_map_physmem() - map a PCI device into memory + * + * This is used on sandbox to map a device into memory so that it can be + * used with normal memory access. After this call, some part of the device's + * internal structure becomes visible. + * + * This function is normally called from sandbox's map_sysmem() automatically. + * + * @paddr: Physical memory address, normally corresponding to a PCI BAR + * @lenp: On entry, the size of the area to map, On exit it is updated + * to the size actually mapped, which may be less if the device + * has less space + * @devp: Returns the device which mapped into this space + * @ptrp: Returns a pointer to the mapped address. The device's space + * can be accessed as @lenp bytes starting here + * Return: 0 if OK, -ve on error + */ +int pci_map_physmem(phys_addr_t paddr, unsigned long *lenp, + struct udevice **devp, void **ptrp); + +/** + * pci_unmap_physmem() - undo a memory mapping + * + * This must be called after pci_map_physmem() to undo the mapping. + * + * @paddr: Physical memory address, as passed to pci_map_physmem() + * @len: Size of area mapped, as returned by pci_map_physmem() + * @dev: Device to unmap, as returned by pci_map_physmem() + * Return: 0 if OK, -ve on error + */ +int pci_unmap_physmem(const void *addr, unsigned long len, + struct udevice *dev); + +/** + * sandbox_set_enable_pci_map() - Enable / disable PCI address mapping + * + * Since address mapping involves calling every driver, provide a way to + * enable and disable this. It can be handled automatically by the emulator + * uclass, which knows if any emulators are currently active. + * + * If this is disabled, pci_map_physmem() will not be called from + * map_sysmem(). + * + * @enable: 0 to disable, 1 to enable + */ +void sandbox_set_enable_pci_map(int enable); + +#endif /* _ASM_SANDBOX_PCI_H_ */ diff --git a/arch/sandbox/include/asm/u-boot-sandbox.h b/arch/sandbox/include/asm/u-boot-sandbox.h index 23eaa3a45e6..3c4347117d4 100644 --- a/arch/sandbox/include/asm/u-boot-sandbox.h +++ b/arch/sandbox/include/asm/u-boot-sandbox.h @@ -14,6 +14,8 @@ #ifndef _U_BOOT_SANDBOX_H_ #define _U_BOOT_SANDBOX_H_ +#include + /* board/.../... */ int board_init(void); @@ -26,54 +28,6 @@ int sandbox_lcd_sdl_early_init(void); struct udevice; -/** - * pci_map_physmem() - map a PCI device into memory - * - * This is used on sandbox to map a device into memory so that it can be - * used with normal memory access. After this call, some part of the device's - * internal structure becomes visible. - * - * This function is normally called from sandbox's map_sysmem() automatically. - * - * @paddr: Physical memory address, normally corresponding to a PCI BAR - * @lenp: On entry, the size of the area to map, On exit it is updated - * to the size actually mapped, which may be less if the device - * has less space - * @devp: Returns the device which mapped into this space - * @ptrp: Returns a pointer to the mapped address. The device's space - * can be accessed as @lenp bytes starting here - * Return: 0 if OK, -ve on error - */ -int pci_map_physmem(phys_addr_t paddr, unsigned long *lenp, - struct udevice **devp, void **ptrp); - -/** - * pci_unmap_physmem() - undo a memory mapping - * - * This must be called after pci_map_physmem() to undo the mapping. - * - * @paddr: Physical memory address, as passed to pci_map_physmem() - * @len: Size of area mapped, as returned by pci_map_physmem() - * @dev: Device to unmap, as returned by pci_map_physmem() - * Return: 0 if OK, -ve on error - */ -int pci_unmap_physmem(const void *addr, unsigned long len, - struct udevice *dev); - -/** - * sandbox_set_enable_pci_map() - Enable / disable PCI address mapping - * - * Since address mapping involves calling every driver, provide a way to - * enable and disable this. It can be handled automatically by the emulator - * uclass, which knows if any emulators are currently active. - * - * If this is disabled, pci_map_physmem() will not be called from - * map_sysmem(). - * - * @enable: 0 to disable, 1 to enable - */ -void sandbox_set_enable_pci_map(int enable); - /** * sandbox_reset() - reset sandbox * diff --git a/drivers/pci/pci-emul-uclass.c b/drivers/pci/pci-emul-uclass.c index 166ee9fcd43..b0b229595ae 100644 --- a/drivers/pci/pci-emul-uclass.c +++ b/drivers/pci/pci-emul-uclass.c @@ -7,9 +7,10 @@ #include #include #include -#include #include +#include #include +#include struct sandbox_pci_emul_priv { int dev_count; diff --git a/test/dm/pci.c b/test/dm/pci.c index bcd274d1879..4f7ee8ab845 100644 --- a/test/dm/pci.c +++ b/test/dm/pci.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include