Merge tag 'fixes-for-v2020.04' of https://gitlab.denx.de/u-boot/custodians/u-boot...
[platform/kernel/u-boot.git] / drivers / misc / swap_case.c
index 18d756e..11189d1 100644 (file)
@@ -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,
 };
@@ -142,25 +139,13 @@ static int sandbox_swap_case_read_config(struct udevice *emul, uint offset,
        case PCI_BASE_ADDRESS_4:
        case PCI_BASE_ADDRESS_5: {
                int barnum;
-               u32 *bar, result;
+               u32 *bar;
 
-               barnum = offset_to_barnum(offset);
+               barnum = pci_offset_to_barnum(offset);
                bar = &plat->bar[barnum];
 
-               result = *bar;
-               if (*bar == 0xffffffff) {
-                       if (barinfo[barnum].type) {
-                               result = (~(barinfo[barnum].size - 1) &
-                                       PCI_BASE_ADDRESS_IO_MASK) |
-                                       PCI_BASE_ADDRESS_SPACE_IO;
-                       } else {
-                               result = (~(barinfo[barnum].size - 1) &
-                                       PCI_BASE_ADDRESS_MEM_MASK) |
-                                       PCI_BASE_ADDRESS_MEM_TYPE_32;
-                       }
-               }
-               debug("r bar %d=%x\n", barnum, result);
-               *valuep = result;
+               *valuep = sandbox_pci_read_bar(*bar, barinfo[barnum].type,
+                                              barinfo[barnum].size);
                break;
        }
        case PCI_CAPABILITY_LIST:
@@ -224,7 +209,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);