I am working on a MD PCI-E driver for the armv7/imx platform. It
attaches via FDT/simplebus, ascertaining its physical memory addresses
from the fdt structure originating from the dtb files present on the
msdos bootloader partition. The dtb files we're using now have the
cubox's 'pcie' nodes disabled via a "status=disabled" property. The
following patches fix this in the decompiled dtb outfiles:
--- imx6q-cubox-i.dts Thu Jul 14 01:26:57 2016
+++ imx6q-cubox-i.post.dts Thu Jul 14 01:27:35 2016
@@ -212,7 +212,7 @@
phandle = <0x46>;
};
- pcie@0x01000000 {
+ pcie@01000000 {
compatible = "fsl,imx6q-pcie", "snps,dw-pcie";
reg = <0x1ffc000 0x4000 0x1f00000 0x80000>;
reg-names = "dbi", "config";
@@ -228,7 +228,6 @@
interrupt-map = <0x0 0x0 0x0 0x1 0x1 0x0 0x7b 0x4 0x0
0x0 0x0 0x2 0x1 0x0 0x7a 0x4 0x0 0x0 0x0 0x3 0x1 0x0 0x79 0x4 0x0 0x0 0x0 0x4
0x1 0x0 0x78 0x4>;
clocks = <0x2 0x90 0x2 0xce 0x2 0xbd>;
clock-names = "pcie", "pcie_bus", "pcie_phy";
- status = "disabled";
};
pmu {
--- imx6dl-cubox-i.dts Thu Jul 14 02:04:27 2016
+++ imx6dl-cubox-i.post.dts Thu Jul 14 02:05:04 2016
@@ -191,7 +191,7 @@
phandle = <0x36>;
};
- pcie@0x01000000 {
+ pcie@01000000 {
compatible = "fsl,imx6q-pcie", "snps,dw-pcie";
reg = <0x1ffc000 0x4000 0x1f00000 0x80000>;
reg-names = "dbi", "config";
@@ -207,7 +207,6 @@
interrupt-map = <0x0 0x0 0x0 0x1 0x1 0x0 0x7b 0x4 0x0
0x0 0x0 0x2 0x1 0x0 0x7a 0x4 0x0 0x0 0x0 0x3 0x1 0x0 0x79 0x4 0x0 0x0 0x0 0x4
0x1 0x0 0x78 0x4>;
clocks = <0x2 0x90 0x2 0xce 0x2 0xbd>;
clock-names = "pcie", "pcie_bus", "pcie_phy";
- status = "disabled";
};
pmu {
Here are the resultant binaries you can copy to your bootloader
partition, for convenience:
http://ce.gl/imx6q-cubox-i.dtb
http://ce.gl/imx6dl-cubox-i.dtb
Replacing these dtbs indeed causes my _match() function to succeed where
it hadn't before.
Finally, here is the (very much in-progress) driver:
Index: sys/arch/armv7/conf/GENERIC
===================================================================
RCS file: /cvs/src/sys/arch/armv7/conf/GENERIC,v
retrieving revision 1.31
diff -u -p -r1.31 GENERIC
--- sys/arch/armv7/conf/GENERIC 12 Jul 2016 19:17:49 -0000 1.31
+++ sys/arch/armv7/conf/GENERIC 14 Jul 2016 06:53:44 -0000
@@ -53,6 +53,7 @@ imxesdhc* at fdt? # SDHC controller
sdmmc* at imxesdhc? # SD/MMC bus
imxahci* at fdt? # AHCI/SATA
imxehci* at fdt? # EHCI
+imxpcie* at fdt? # PCI-E
usb* at imxehci?
# OMAP3xxx/OMAP4xxx SoC
Index: sys/arch/armv7/imx/files.imx
===================================================================
RCS file: /cvs/src/sys/arch/armv7/imx/files.imx,v
retrieving revision 1.15
diff -u -p -r1.15 files.imx
--- sys/arch/armv7/imx/files.imx 12 Jul 2016 19:17:49 -0000 1.15
+++ sys/arch/armv7/imx/files.imx 14 Jul 2016 06:53:44 -0000
@@ -51,3 +51,7 @@ file arch/armv7/imx/imxesdhc.c imxesdhc
device imxahci: scsi, atascsi
attach imxahci at fdt
file arch/armv7/imx/imxahci.c imxahci
+
+device imxpcie
+attach imxpcie at fdt
+file arch/armv7/imx/imxpcie.c imxpcie
Index: sys/arch/armv7/imx/imxpcie.c
===================================================================
RCS file: sys/arch/armv7/imx/imxpcie.c
diff -N sys/arch/armv7/imx/imxpcie.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ sys/arch/armv7/imx/imxpcie.c 14 Jul 2016 06:53:44 -0000
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2016 Ian Sutton <[email protected]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+
+#include <machine/bus.h>
+#include <machine/fdt.h>
+
+#include <dev/ofw/fdt.h>
+#include <dev/ofw/openfirm.h>
+
+#include "imxpcievar.h"
+
+int imxpcie_match(struct device *, void *, void *);
+void imxpcie_attach(struct device *, struct device *, void *);
+
+#define HREAD4(sc, reg)
\
+ (bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (reg)))
+#define HWRITE4(sc, reg, val) \
+ bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))
+#define HSET4(sc, reg, bits) \
+ HWRITE4((sc), (reg), HREAD4((sc), (reg)) | (bits))
+#define HCLR4(sc, reg, bits) \
+ HWRITE4((sc), (reg), HREAD4((sc), (reg)) & ~(bits))
+
+#define DEVNAME(sc) (sc)->sc_dev.dv_xname
+#define DEVUNIT(x) (minor(x) & 0x7f)
+
+struct imxpcie_softc {
+ struct device sc_dev;
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_ioh;
+};
+
+struct cfattach imxpcie_ca = {
+ sizeof(struct imxpcie_softc), imxpcie_match, imxpcie_attach
+};
+
+struct cfdriver imxpcie_cd = {
+ NULL, "imxpcie", DV_DULL
+};
+
+int
+imxpcie_match(struct device *parent, void *match, void *aux)
+{
+ struct fdt_attach_args *faa = aux;
+ return OF_is_compatible(faa->fa_node, "fsl,imx6q-pcie");
+}
+
+void
+imxpcie_attach(struct device *parent, struct device *self, void *args)
+{
+ struct fdt_attach_args *aa = args;
+ struct imxpcie_softc *sc = (struct imxpcie_softc *) self;
+
+ sc->sc_iot = aa->fa_iot;
+ if (bus_space_map(sc->sc_iot, aa->fa_reg[0],
+ aa->fa_reg[1], 0, &sc->sc_ioh))
+ panic("%s: bus_space_map failed!", __func__);
+
+ printf("\n");
+}
Index: sys/arch/armv7/imx/imxpcievar.h
===================================================================
RCS file: sys/arch/armv7/imx/imxpcievar.h
diff -N sys/arch/armv7/imx/imxpcievar.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ sys/arch/armv7/imx/imxpcievar.h 14 Jul 2016 06:53:44 -0000
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2016 Ian Sutton <[email protected]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+