[U-Boot] [PATCH 22/22] dm: pci: Add driver model tests for PCI

Simon Glass sjg at chromium.org
Wed Feb 18 22:10:49 CET 2015


Add some basic tests to check that things work as expected with sandbox.

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

 test/dm/Makefile |  1 +
 test/dm/pci.c    | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/dm/test.dts | 17 ++++++++++++++++
 3 files changed, 77 insertions(+)
 create mode 100644 test/dm/pci.c

diff --git a/test/dm/Makefile b/test/dm/Makefile
index 612aa95..8281779 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_DM_GPIO) += gpio.o
 obj-$(CONFIG_DM_SPI) += spi.o
 obj-$(CONFIG_DM_SPI_FLASH) += sf.o
 obj-$(CONFIG_DM_I2C) += i2c.o
+obj-$(CONFIG_DM_PCI) += pci.o
 endif
diff --git a/test/dm/pci.c b/test/dm/pci.c
new file mode 100644
index 0000000..6c63fa4
--- /dev/null
+++ b/test/dm/pci.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2015 Google, Inc
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <asm/io.h>
+#include <dm/test.h>
+#include <dm/ut.h>
+
+/* Test that sandbox PCI works correctly */
+static int dm_test_pci_base(struct dm_test_state *dms)
+{
+	struct udevice *bus;
+
+	ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus));
+
+	return 0;
+}
+DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that we can use the swapcase device correctly */
+static int dm_test_pci_swapcase(struct dm_test_state *dms)
+{
+	pci_dev_t pci_dev = PCI_BDF(0, 0x1f, 0);
+	struct pci_controller *hose;
+	struct udevice *bus, *swap;
+	ulong io_addr, mem_addr;
+	char *ptr;
+
+	/* Check that asking for the device automatically fires up PCI */
+	ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &swap));
+
+	ut_assertok(uclass_get_device(UCLASS_PCI, 0, &bus));
+	hose = dev_get_uclass_priv(bus);
+
+	/* First test I/O */
+	io_addr = pci_read_bar32(hose, pci_dev, 0);
+	outb(2, io_addr);
+	ut_asserteq(2, inb(io_addr));
+
+	/*
+	 * Now test memory mapping - note we must unmap and remap to cause
+	 * the swapcase emulation to see our data and response.
+	 */
+	mem_addr = pci_read_bar32(hose, pci_dev, 1);
+	ptr = map_sysmem(mem_addr, 20);
+	strcpy(ptr, "This is a TesT");
+	unmap_sysmem(ptr);
+
+	ptr = map_sysmem(mem_addr, 20);
+	ut_asserteq_str("tHIS IS A tESt", ptr);
+	unmap_sysmem(ptr);
+
+	return 0;
+}
+DM_TEST(dm_test_pci_swapcase, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/test.dts b/test/dm/test.dts
index 84024a4..96775e1 100644
--- a/test/dm/test.dts
+++ b/test/dm/test.dts
@@ -10,6 +10,7 @@
 		console = &uart0;
 		i2c0 = "/i2c at 0";
 		spi0 = "/spi at 0";
+		pci0 = &pci;
 		testfdt6 = "/e-test";
 		testbus3 = "/some-bus";
 		testfdt0 = "/some-bus/c-test at 0";
@@ -135,6 +136,22 @@
 		};
 	};
 
+	pci: pci-controller {
+		compatible = "sandbox,pci";
+		device_type = "pci";
+		#address-cells = <3>;
+		#size-cells = <2>;
+		ranges = <0x02000000 0 0x10000000 0x10000000 0 0x2000
+				0x01000000 0 0x20000000 0x20000000 0 0x2000>;
+		pci at 1f,0 {
+			compatible = "pci-generic";
+			reg = <0xf800 0 0 0 0>;
+			emul at 1f,0 {
+				compatible = "sandbox,swap-case";
+			};
+		};
+	};
+
 	spi at 0 {
 		#address-cells = <1>;
 		#size-cells = <0>;
-- 
2.2.0.rc0.207.ga3a616c



More information about the U-Boot mailing list