summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2017-07-28 14:54:14 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2017-07-28 14:54:14 +0000
commit9624af7930a891f7ff8639f6158e54b4e8b99f39 (patch)
tree086d903fcb4424793d4b0c9592b160859331bf1d
parentb3d2901aeab43e0ff7f9c84acf13029282b9ee99 (diff)
Add a driver for the OCTEON SATA controller bridge.
OK deraadt@, jasper@, kettenis@
-rw-r--r--sys/arch/octeon/conf/GENERIC6
-rw-r--r--sys/arch/octeon/conf/RAMDISK6
-rw-r--r--sys/arch/octeon/conf/files.octeon8
-rw-r--r--sys/arch/octeon/dev/octsctl.c135
-rw-r--r--sys/dev/fdt/ahci_fdt.c3
5 files changed, 154 insertions, 4 deletions
diff --git a/sys/arch/octeon/conf/GENERIC b/sys/arch/octeon/conf/GENERIC
index d0c1d7fc13d..aa3d913d504 100644
--- a/sys/arch/octeon/conf/GENERIC
+++ b/sys/arch/octeon/conf/GENERIC
@@ -1,4 +1,4 @@
-# $OpenBSD: GENERIC,v 1.36 2017/07/25 11:01:28 jmatthew Exp $
+# $OpenBSD: GENERIC,v 1.37 2017/07/28 14:54:12 visa Exp $
#
# For further information on compiling OpenBSD kernels, see the config(8)
# man page.
@@ -69,6 +69,10 @@ pciide* at pci? flags 0x0000
# IDE hard drives
wd* at pciide? flags 0x0000
+# AHCI controllers
+octsctl* at fdt?
+ahci* at octsctl?
+
# USB Controllers
dwctwo0 at iobus? irq 56
octuctl* at fdt?
diff --git a/sys/arch/octeon/conf/RAMDISK b/sys/arch/octeon/conf/RAMDISK
index e1d0a45e2b8..a598d5be079 100644
--- a/sys/arch/octeon/conf/RAMDISK
+++ b/sys/arch/octeon/conf/RAMDISK
@@ -1,4 +1,4 @@
-# $OpenBSD: RAMDISK,v 1.34 2017/07/25 11:01:28 jmatthew Exp $
+# $OpenBSD: RAMDISK,v 1.35 2017/07/28 14:54:12 visa Exp $
machine octeon mips64
maxusers 4
@@ -61,6 +61,10 @@ cnmac* at cn30xxgmx?
pciide* at pci? flags 0x0000
wd* at pciide? flags 0x0000
+# AHCI controllers
+octsctl* at fdt?
+ahci* at octsctl?
+
dwctwo0 at iobus0 irq 56
octuctl* at fdt?
ehci0 at octuctl?
diff --git a/sys/arch/octeon/conf/files.octeon b/sys/arch/octeon/conf/files.octeon
index 9dec1c6d164..73da3a6fb89 100644
--- a/sys/arch/octeon/conf/files.octeon
+++ b/sys/arch/octeon/conf/files.octeon
@@ -1,4 +1,4 @@
-# $OpenBSD: files.octeon,v 1.40 2017/07/25 11:01:28 jmatthew Exp $
+# $OpenBSD: files.octeon,v 1.41 2017/07/28 14:54:12 visa Exp $
# Standard stanzas config(8) can't run without
maxpartitions 16
@@ -76,6 +76,8 @@ device simplebus: fdt
attach simplebus at fdt, iobus
file arch/octeon/dev/simplebus.c simplebus
+include "dev/fdt/files.fdt"
+
# On-board USB
attach dwctwo at iobus with octdwctwo
file arch/octeon/dev/octdwctwo.c octdwctwo needs-flag
@@ -137,5 +139,9 @@ device octmmc: sdmmcbus
attach octmmc at fdt
file arch/octeon/dev/octmmc.c octmmc
+device octsctl: fdt
+attach octsctl at fdt
+file arch/octeon/dev/octsctl.c octsctl
+
pseudo-device openprom
file arch/octeon/octeon/openprom.c openprom needs-flag
diff --git a/sys/arch/octeon/dev/octsctl.c b/sys/arch/octeon/dev/octsctl.c
new file mode 100644
index 00000000000..f49b54ec839
--- /dev/null
+++ b/sys/arch/octeon/dev/octsctl.c
@@ -0,0 +1,135 @@
+/* $OpenBSD: octsctl.c,v 1.1 2017/07/28 14:54:13 visa Exp $ */
+
+/*
+ * Copyright (c) 2017 Visa Hankala
+ *
+ * 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.
+ */
+
+/*
+ * Driver for OCTEON SATA controller bridge.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+
+#include <machine/bus.h>
+#include <machine/fdt.h>
+
+#include <dev/ofw/fdt.h>
+#include <dev/ofw/openfirm.h>
+
+#define SCTL_SHIM_CFG 0xe8
+#define SCTL_SHIM_CFG_READ_CMD 0x0000000000001000ul
+#define SCTL_SHIM_CFG_DMA_BYTE_SWAP 0x0000000000000300ul
+#define SCTL_SHIM_CFG_DMA_BYTE_SWAP_SHIFT 8
+#define SCTL_SHIM_CFG_CSR_BYTE_SWAP 0x0000000000000003ul
+#define SCTL_SHIM_CFG_CSR_BYTE_SWAP_SHIFT 0
+
+struct octsctl_softc {
+ struct device sc_dev;
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_ioh;
+};
+
+int octsctl_match(struct device *, void *, void *);
+void octsctl_attach(struct device *, struct device *, void *);
+
+const struct cfattach octsctl_ca = {
+ sizeof(struct octsctl_softc), octsctl_match, octsctl_attach
+};
+
+struct cfdriver octsctl_cd = {
+ NULL, "octsctl", DV_DULL
+};
+
+int
+octsctl_match(struct device *parent, void *match, void *aux)
+{
+ struct fdt_attach_args *faa = aux;
+
+ /*
+ * On some machines, the bridge controller node does not have
+ * an AHCI controller node as a child.
+ */
+
+ return OF_is_compatible(faa->fa_node, "cavium,octeon-7130-sata-uctl") &&
+ OF_child(faa->fa_node) != 0;
+}
+
+void
+octsctl_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct fdt_reg child_reg;
+ struct fdt_attach_args child_faa;
+ struct fdt_attach_args *faa = aux;
+ struct octsctl_softc *sc = (struct octsctl_softc *)self;
+ uint64_t val;
+ uint32_t reg[4];
+ int child;
+
+ if (faa->fa_nreg != 1) {
+ printf(": expected one IO space, got %d\n", faa->fa_nreg);
+ return;
+ }
+
+ child = OF_child(faa->fa_node);
+ if (OF_getpropint(faa->fa_node, "#address-cells", 0) != 2 ||
+ OF_getpropint(faa->fa_node, "#size-cells", 0) != 2) {
+ printf(": invalid fdt reg cells\n");
+ return;
+ }
+ if (OF_getproplen(child, "reg") != sizeof(reg)) {
+ printf(": invalid child fdt reg\n");
+ return;
+ }
+ OF_getpropintarray(child, "reg", reg, sizeof(reg));
+ child_reg.addr = ((uint64_t)reg[0] << 32) | reg[1];
+ child_reg.size = ((uint64_t)reg[2] << 32) | reg[3];
+
+ sc->sc_iot = faa->fa_iot;
+ if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, faa->fa_reg[0].size,
+ 0, &sc->sc_ioh)) {
+ printf(": could not map registers\n");
+ goto error;
+ }
+
+ val = bus_space_read_8(sc->sc_iot, sc->sc_ioh, SCTL_SHIM_CFG);
+ val &= ~SCTL_SHIM_CFG_CSR_BYTE_SWAP;
+ val &= ~SCTL_SHIM_CFG_DMA_BYTE_SWAP;
+ val |= 3ul << SCTL_SHIM_CFG_CSR_BYTE_SWAP_SHIFT;
+ val |= 1ul << SCTL_SHIM_CFG_DMA_BYTE_SWAP_SHIFT;
+ val |= SCTL_SHIM_CFG_READ_CMD;
+ bus_space_write_8(sc->sc_iot, sc->sc_ioh, SCTL_SHIM_CFG, val);
+ (void)bus_space_read_8(sc->sc_iot, sc->sc_ioh, SCTL_SHIM_CFG);
+
+ printf("\n");
+
+ memset(&child_faa, 0, sizeof(child_faa));
+ child_faa.fa_name = "";
+ child_faa.fa_node = child;
+ child_faa.fa_iot = faa->fa_iot;
+ child_faa.fa_dmat = faa->fa_dmat;
+ child_faa.fa_reg = &child_reg;
+ child_faa.fa_nreg = 1;
+ /* child_faa.fa_intr is not utilized. */
+
+ config_found(self, &child_faa, NULL);
+
+ return;
+
+error:
+ if (sc->sc_ioh != 0)
+ bus_space_unmap(sc->sc_iot, sc->sc_ioh, faa->fa_reg[0].size);
+}
diff --git a/sys/dev/fdt/ahci_fdt.c b/sys/dev/fdt/ahci_fdt.c
index fbf5546fe9e..d28fc588cb4 100644
--- a/sys/dev/fdt/ahci_fdt.c
+++ b/sys/dev/fdt/ahci_fdt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ahci_fdt.c,v 1.2 2017/02/24 17:12:31 patrick Exp $ */
+/* $OpenBSD: ahci_fdt.c,v 1.3 2017/07/28 14:54:13 visa Exp $ */
/*
* Copyright (c) 2013,2017 Patrick Wildt <patrick@blueri.se>
*
@@ -53,6 +53,7 @@ ahci_fdt_match(struct device *parent, void *match, void *aux)
struct fdt_attach_args *faa = aux;
return OF_is_compatible(faa->fa_node, "generic-ahci") ||
+ OF_is_compatible(faa->fa_node, "cavium,octeon-7130-ahci") ||
OF_is_compatible(faa->fa_node, "snps,dwc-ahci");
}