Allow com(4) to make use of the simplebus address translation.
authorpatrick <patrick@openbsd.org>
Mon, 15 Aug 2016 14:17:34 +0000 (14:17 +0000)
committerpatrick <patrick@openbsd.org>
Mon, 15 Aug 2016 14:17:34 +0000 (14:17 +0000)
This typically works for every simplebus client, but com(4) did not
make use of the supplied bus tag.  Instead it references the global
a4x bus tag.  This is needed as the ARM com(4) controllers use 4-byte
spaced registers, while com(4) operates on 1-byte.  To be able to make
use of the address translation, copy the a4x bus tag and replace the
cookie and map function with the one supplied by simplebus.

ok kettenis@

sys/arch/armv7/dev/com_fdt.c

index 9e83c24..e72da18 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: com_fdt.c,v 1.1 2016/08/15 13:42:49 patrick Exp $ */
+/* $OpenBSD: com_fdt.c,v 1.2 2016/08/15 14:17:34 patrick Exp $ */
 /*
  * Copyright 2003 Wasabi Systems, Inc.
  * All rights reserved.
@@ -66,8 +66,13 @@ int  com_fdt_activate(struct device *, int);
 extern int comcnspeed;
 extern int comcnmode;
 
+struct com_fdt_softc {
+       struct com_softc         sc;
+       struct bus_space         sc_iot;
+};
+
 struct cfattach com_fdt_ca = {
-       sizeof (struct com_softc), com_fdt_match, com_fdt_attach, NULL,
+       sizeof (struct com_fdt_softc), com_fdt_match, com_fdt_attach, NULL,
        com_fdt_activate
 };
 
@@ -100,29 +105,37 @@ com_fdt_match(struct device *parent, void *match, void *aux)
 void
 com_fdt_attach(struct device *parent, struct device *self, void *aux)
 {
-       struct com_softc *sc = (struct com_softc *)self;
+       struct com_fdt_softc *sc = (struct com_fdt_softc *)self;
        struct fdt_attach_args *faa = aux;
 
        if (faa->fa_nreg < 1)
                return;
 
-       sc->sc_iot = &armv7_a4x_bs_tag; /* XXX: This sucks */
-       sc->sc_iobase = faa->fa_reg[0].addr;
-       sc->sc_frequency = 48000000;
-       sc->sc_uarttype = COM_UART_TI16750;
-
-       if (bus_space_map(sc->sc_iot, sc->sc_iobase,
-           faa->fa_reg[0].size, 0, &sc->sc_ioh)) {
+       /*
+        * XXX This sucks.  We need to get rid of the a4x bus tag
+        * altogether.  For this we will need to change com(4).
+        */
+       sc->sc_iot = armv7_a4x_bs_tag;
+       sc->sc_iot.bs_cookie = faa->fa_iot->bs_cookie;
+       sc->sc_iot.bs_map = faa->fa_iot->bs_map;
+
+       sc->sc.sc_iot = &sc->sc_iot;
+       sc->sc.sc_iobase = faa->fa_reg[0].addr;
+       sc->sc.sc_frequency = 48000000;
+       sc->sc.sc_uarttype = COM_UART_TI16750;
+
+       if (bus_space_map(sc->sc.sc_iot, sc->sc.sc_iobase,
+           faa->fa_reg[0].size, 0, &sc->sc.sc_ioh)) {
                printf("%s: bus_space_map failed\n", __func__);
                return;
        }
 
        pinctrl_byname(faa->fa_node, "default");
 
-       com_attach_subr(sc);
+       com_attach_subr(&sc->sc);
 
        (void)arm_intr_establish_fdt(faa->fa_node, IPL_TTY, comintr,
-           sc, sc->sc_dev.dv_xname);
+           sc, sc->sc.sc_dev.dv_xname);
 }
 
 int