diff mbox series

[U-Boot,022/126] sandbox: pci: Move pci_offset_to_barnum() to pci.h

Message ID 20190925145750.200592-23-sjg@chromium.org
State Accepted
Commit 37a1cf9c9c4c670e074feb8fb2fc6b4a40a80b1b
Delegated to: Bin Meng
Headers show
Series x86: Add initial support for apollolake | expand

Commit Message

Simon Glass Sept. 25, 2019, 2:56 p.m. UTC
This function is useful in PCI emulators. More it into the header file to
avoid duplicating it in other drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/swap_case.c | 7 ++-----
 include/pci.h            | 4 ++++
 2 files changed, 6 insertions(+), 5 deletions(-)

Comments

Bin Meng Oct. 5, 2019, 2:17 a.m. UTC | #1
On Wed, Sep 25, 2019 at 10:58 PM Simon Glass <sjg@chromium.org> wrote:
>
> This function is useful in PCI emulators. More it into the header file to
> avoid duplicating it in other drivers.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/misc/swap_case.c | 7 ++-----
>  include/pci.h            | 4 ++++
>  2 files changed, 6 insertions(+), 5 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Bin Meng Oct. 6, 2019, 10:03 a.m. UTC | #2
On Sat, Oct 5, 2019 at 10:17 AM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> On Wed, Sep 25, 2019 at 10:58 PM Simon Glass <sjg@chromium.org> wrote:
> >
> > This function is useful in PCI emulators. More it into the header file to
> > avoid duplicating it in other drivers.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> >  drivers/misc/swap_case.c | 7 ++-----
> >  include/pci.h            | 4 ++++
> >  2 files changed, 6 insertions(+), 5 deletions(-)
> >
>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

applied to u-boot-x86/next, thanks!
diff mbox series

Patch

diff --git a/drivers/misc/swap_case.c b/drivers/misc/swap_case.c
index 18d756e9cd5..75fe6416707 100644
--- a/drivers/misc/swap_case.c
+++ b/drivers/misc/swap_case.c
@@ -24,9 +24,6 @@  struct swap_case_platdata {
 	u32 bar[6];
 };
 
-#define offset_to_barnum(offset)	\
-		(((offset) - PCI_BASE_ADDRESS_0) / sizeof(u32))
-
 enum {
 	MEM_TEXT_SIZE	= 0x100,
 };
@@ -144,7 +141,7 @@  static int sandbox_swap_case_read_config(struct udevice *emul, uint offset,
 		int barnum;
 		u32 *bar, result;
 
-		barnum = offset_to_barnum(offset);
+		barnum = pci_offset_to_barnum(offset);
 		bar = &plat->bar[barnum];
 
 		result = *bar;
@@ -224,7 +221,7 @@  static int sandbox_swap_case_write_config(struct udevice *emul, uint offset,
 		int barnum;
 		u32 *bar;
 
-		barnum = offset_to_barnum(offset);
+		barnum = pci_offset_to_barnum(offset);
 		bar = &plat->bar[barnum];
 
 		debug("w bar %d=%lx\n", barnum, value);
diff --git a/include/pci.h b/include/pci.h
index 999a594cddf..2b82b2c5a3e 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -215,6 +215,10 @@ 
 #define  PCI_BASE_ADDRESS_IO_MASK	(~0x03ULL)
 /* bit 1 is reserved if address_space = 1 */
 
+/* Convert a regsister address (e.g. PCI_BASE_ADDRESS_1) to a bar # (e.g. 1) */
+#define pci_offset_to_barnum(offset)	\
+		(((offset) - PCI_BASE_ADDRESS_0) / sizeof(u32))
+
 /* Header type 0 (normal devices) */
 #define PCI_CARDBUS_CIS		0x28
 #define PCI_SUBSYSTEM_VENDOR_ID 0x2c