The diff below extends the register width/shift support in com(4) such
that the serial console on armv7 and arm64 doesn't have to use the
nasty bus space hacks anymore. I removed the com_common_getc() and
com_common_putc() functions as they didn't really serve any purpose
anymore. The equivalent code is now simply part of comcngetc() and
comcnputc().
ok?
Index: arch/arm64/dev/com_fdt.c
===================================================================
RCS file: /cvs/src/sys/arch/arm64/dev/com_fdt.c,v
retrieving revision 1.5
diff -u -p -r1.5 com_fdt.c
--- arch/arm64/dev/com_fdt.c 6 May 2018 17:16:48 -0000 1.5
+++ arch/arm64/dev/com_fdt.c 13 May 2018 21:04:41 -0000
@@ -28,8 +28,6 @@
#include <dev/ic/comvar.h>
#include <dev/cons.h>
-#include <arm64/arm64/arm64var.h>
-
#include <dev/ofw/fdt.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_clock.h>
@@ -45,12 +43,8 @@ struct cfattach com_fdt_ca = {
sizeof (struct com_softc), com_fdt_match, com_fdt_attach
};
-int com_fdt_cngetc(dev_t);
-void com_fdt_cnputc(dev_t, int);
-void com_fdt_cnpollc(dev_t, int);
-
struct consdev com_fdt_cons = {
- NULL, NULL, com_fdt_cngetc, com_fdt_cnputc, com_fdt_cnpollc, NULL,
+ NULL, NULL, comcngetc, comcnputc, comcnpollc, NULL,
NODEV, CN_LOWPRI
};
@@ -76,7 +70,10 @@ com_fdt_init_cons(void)
* comcnattach() does by doing the minimal setup here.
*/
- comconsiot = &arm64_a4x_bs_tag;
+ comcons_reg_width = OF_getpropint(stdout_node, "reg-io-width", 4);
+ comcons_reg_shift = OF_getpropint(stdout_node, "reg-shift", 2);
+
+ comconsiot = fdt_cons_bs_tag;
if (bus_space_map(comconsiot, reg.addr, reg.size, 0, &comconsioh))
return;
@@ -160,21 +157,4 @@ com_fdt_intr_designware(void *cookie)
com_read_reg(sc, com_usr);
return comintr(sc);
-}
-
-int
-com_fdt_cngetc(dev_t dev)
-{
- return com_common_getc(comconsiot, comconsioh);
-}
-
-void
-com_fdt_cnputc(dev_t dev, int c)
-{
- com_common_putc(comconsiot, comconsioh, c);
-}
-
-void
-com_fdt_cnpollc(dev_t dev, int on)
-{
}
Index: arch/armv7/dev/com_fdt.c
===================================================================
RCS file: /cvs/src/sys/arch/armv7/dev/com_fdt.c,v
retrieving revision 1.12
diff -u -p -r1.12 com_fdt.c
--- arch/armv7/dev/com_fdt.c 7 May 2018 14:13:54 -0000 1.12
+++ arch/armv7/dev/com_fdt.c 13 May 2018 21:04:41 -0000
@@ -28,9 +28,6 @@
#include <dev/ic/comvar.h>
#include <dev/cons.h>
-/* pick up armv7_a4x_bs_tag */
-#include <arch/arm/armv7/armv7var.h>
-
#include <dev/ofw/fdt.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_clock.h>
@@ -49,12 +46,8 @@ struct cfattach com_fdt_ca = {
sizeof (struct com_softc), com_fdt_match, com_fdt_attach
};
-int com_fdt_cngetc(dev_t);
-void com_fdt_cnputc(dev_t, int);
-void com_fdt_cnpollc(dev_t, int);
-
struct consdev com_fdt_cons = {
- NULL, NULL, com_fdt_cngetc, com_fdt_cnputc, com_fdt_cnpollc, NULL,
+ NULL, NULL, comcngetc, comcnputc, comcnpollc, NULL,
NODEV, CN_LOWPRI
};
@@ -80,7 +73,10 @@ com_fdt_init_cons(void)
* comcnattach() does by doing the minimal setup here.
*/
- comconsiot = &armv7_a4x_bs_tag;
+ comcons_reg_width = OF_getpropint(stdout_node, "reg-io-width", 4);
+ comcons_reg_shift = OF_getpropint(stdout_node, "reg-shift", 2);
+
+ comconsiot = fdt_cons_bs_tag;
if (bus_space_map(comconsiot, reg.addr, reg.size, 0, &comconsioh))
return;
@@ -165,21 +161,4 @@ com_fdt_intr_designware(void *cookie)
com_read_reg(sc, com_usr);
return comintr(sc);
-}
-
-int
-com_fdt_cngetc(dev_t dev)
-{
- return com_common_getc(comconsiot, comconsioh);
-}
-
-void
-com_fdt_cnputc(dev_t dev, int c)
-{
- com_common_putc(comconsiot, comconsioh, c);
-}
-
-void
-com_fdt_cnpollc(dev_t dev, int on)
-{
}
Index: dev/ic/com.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/com.c,v
retrieving revision 1.168
diff -u -p -r1.168 com.c
--- dev/ic/com.c 2 May 2018 13:20:12 -0000 1.168
+++ dev/ic/com.c 13 May 2018 21:04:42 -0000
@@ -1133,52 +1133,6 @@ comintr(void *arg)
}
}
-/*
- * The following functions are polled getc and putc routines, used
- * by the console glue.
- */
-
-int
-com_common_getc(bus_space_tag_t iot, bus_space_handle_t ioh)
-{
- int s = splhigh();
- u_char stat, c;
-
- /* Block until a character becomes available. */
- while (!ISSET(stat = bus_space_read_1(iot, ioh, com_lsr), LSR_RXRDY))
- continue;
-
- c = bus_space_read_1(iot, ioh, com_data);
-
- /* Clear any interrupts generated by this transmission. */
- stat = bus_space_read_1(iot, ioh, com_iir);
- splx(s);
- return (c);
-}
-
-void
-com_common_putc(bus_space_tag_t iot, bus_space_handle_t ioh, int c)
-{
- int s = spltty();
- int timo;
-
- /* Wait for any pending transmission to finish. */
- timo = 2000;
- while (!ISSET(bus_space_read_1(iot, ioh, com_lsr), LSR_TXRDY) && --timo)
- delay(1);
-
- bus_space_write_1(iot, ioh, com_data, (u_int8_t)(c & 0xff));
- bus_space_barrier(iot, ioh, 0, COM_NPORTS,
- (BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE));
-
- /* Wait for this transmission to complete. */
- timo = 2000;
- while (!ISSET(bus_space_read_1(iot, ioh, com_lsr), LSR_TXRDY) && --timo)
- delay(1);
-
- splx(s);
-}
-
void
cominit(bus_space_tag_t iot, bus_space_handle_t ioh, int rate, int frequency)
{
@@ -1267,7 +1221,19 @@ comcnattach(bus_space_tag_t iot, bus_add
int
comcngetc(dev_t dev)
{
- return (com_common_getc(comconsiot, comconsioh));
+ int s = splhigh();
+ u_char stat, c;
+
+ /* Block until a character becomes available. */
+ while (!ISSET(stat = comcn_read_reg(com_lsr), LSR_RXRDY))
+ continue;
+
+ c = comcn_read_reg(com_data);
+
+ /* Clear any interrupts generated by this transmission. */
+ stat = comcn_read_reg(com_iir);
+ splx(s);
+ return (c);
}
/*
@@ -1276,13 +1242,30 @@ comcngetc(dev_t dev)
void
comcnputc(dev_t dev, int c)
{
- com_common_putc(comconsiot, comconsioh, c);
+ int s = spltty();
+ int timo;
+
+ /* Wait for any pending transmission to finish. */
+ timo = 2000;
+ while (!ISSET(comcn_read_reg(com_lsr), LSR_TXRDY) && --timo)
+ delay(1);
+
+ comcn_write_reg(com_data, (u_int8_t)(c & 0xff));
+ bus_space_barrier(comconsiot, comconsioh, 0,
+ COM_NPORTS << comcons_reg_shift,
+ (BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE));
+
+ /* Wait for this transmission to complete. */
+ timo = 2000;
+ while (!ISSET(comcn_read_reg(com_lsr), LSR_TXRDY) && --timo)
+ delay(1);
+
+ splx(s);
}
void
comcnpollc(dev_t dev, int on)
{
-
}
#endif /* COM_CONSOLE */
@@ -1615,3 +1598,32 @@ com_write_reg(struct com_softc *sc, bus_
else
return bus_space_write_1(sc->sc_iot, sc->sc_ioh, reg, value);
}
+
+#ifdef COM_CONSOLE
+
+u_char comcons_reg_width;
+u_char comcons_reg_shift;
+
+uint8_t
+comcn_read_reg(bus_size_t reg)
+{
+ reg <<= comcons_reg_shift;
+
+ if (comcons_reg_width == 4)
+ return bus_space_read_4(comconsiot, comconsioh, reg);
+ else
+ return bus_space_read_1(comconsiot, comconsioh, reg);
+}
+
+void
+comcn_write_reg(bus_size_t reg, uint8_t value)
+{
+ reg <<= comcons_reg_shift;
+
+ if (comcons_reg_width == 4)
+ return bus_space_write_4(comconsiot, comconsioh, reg, value);
+ else
+ return bus_space_write_1(comconsiot, comconsioh, reg, value);
+}
+
+#endif
Index: dev/ic/comvar.h
===================================================================
RCS file: /cvs/src/sys/dev/ic/comvar.h,v
retrieving revision 1.56
diff -u -p -r1.56 comvar.h
--- dev/ic/comvar.h 2 May 2018 13:20:12 -0000 1.56
+++ dev/ic/comvar.h 13 May 2018 21:04:42 -0000
@@ -150,6 +150,9 @@ int comparam(struct tty *, struct termio
void comstart(struct tty *);
void comsoft(void *);
+uint8_t comcn_read_reg(bus_size_t);
+void comcn_write_reg(bus_size_t, uint8_t);
+
struct consdev;
int comcnattach(bus_space_tag_t, bus_addr_t, int, int, tcflag_t);
void comcnprobe(struct consdev *);
@@ -157,8 +160,6 @@ void comcninit(struct consdev *);
int comcngetc(dev_t);
void comcnputc(dev_t, int);
void comcnpollc(dev_t, int);
-int com_common_getc(bus_space_tag_t, bus_space_handle_t);
-void com_common_putc(bus_space_tag_t, bus_space_handle_t, int);
void com_raisedtr(void *);
void com_attach_subr(struct com_softc *);
@@ -173,3 +174,5 @@ extern bus_space_tag_t comconsiot;
extern bus_space_handle_t comconsioh;
extern int comconsunit;
extern tcflag_t comconscflag;
+extern u_char comcons_reg_width;
+extern u_char comcons_reg_shift;