diff options
author | 2018-07-02 12:46:20 +0000 | |
---|---|---|
committer | 2018-07-02 12:46:20 +0000 | |
commit | e474e71d971d949f633c4210bda2bcbbdf16a70c (patch) | |
tree | d0f8a6c537013c36dc27247e9f31579f622c0217 | |
parent | Fire notify for select-layout, from George Nachman. (diff) | |
download | wireguard-openbsd-e474e71d971d949f633c4210bda2bcbbdf16a70c.tar.xz wireguard-openbsd-e474e71d971d949f633c4210bda2bcbbdf16a70c.zip |
Allow pluart(4) to attach to acpi(4).
ok mlarkin@, patrick@
-rw-r--r-- | sys/arch/arm64/conf/GENERIC | 3 | ||||
-rw-r--r-- | sys/arch/arm64/conf/RAMDISK | 3 | ||||
-rw-r--r-- | sys/conf/files | 6 | ||||
-rw-r--r-- | sys/dev/acpi/files.acpi | 6 | ||||
-rw-r--r-- | sys/dev/acpi/pluart_acpi.c | 153 | ||||
-rw-r--r-- | sys/dev/fdt/files.fdt | 7 | ||||
-rw-r--r-- | sys/dev/fdt/pluart_fdt.c | 80 | ||||
-rw-r--r-- | sys/dev/ic/pluart.c (renamed from sys/dev/fdt/pluart.c) | 100 | ||||
-rw-r--r-- | sys/dev/ic/pluartvar.h | 63 |
9 files changed, 317 insertions, 104 deletions
diff --git a/sys/arch/arm64/conf/GENERIC b/sys/arch/arm64/conf/GENERIC index 89cf019796a..a2fc289b179 100644 --- a/sys/arch/arm64/conf/GENERIC +++ b/sys/arch/arm64/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.75 2018/07/02 11:23:19 kettenis Exp $ +# $OpenBSD: GENERIC,v 1.76 2018/07/02 12:46:20 kettenis Exp $ # # GENERIC machine description file # @@ -42,6 +42,7 @@ acpibtn* at acpi? acpiec* at acpi? ahci* at acpi? com* at acpi? +pluart* at acpi? xhci* at acpi? simplebus* at fdt? diff --git a/sys/arch/arm64/conf/RAMDISK b/sys/arch/arm64/conf/RAMDISK index 43ed1adaf7a..471bcdeecdc 100644 --- a/sys/arch/arm64/conf/RAMDISK +++ b/sys/arch/arm64/conf/RAMDISK @@ -1,4 +1,4 @@ -# $OpenBSD: RAMDISK,v 1.62 2018/07/02 11:23:19 kettenis Exp $ +# $OpenBSD: RAMDISK,v 1.63 2018/07/02 12:46:20 kettenis Exp $ # # GENERIC machine description file # @@ -52,6 +52,7 @@ acpi0 at mainbus? acpiec* at acpi? ahci* at acpi? com* at acpi? +pluart* at acpi? xhci* at acpi? simplebus* at fdt? diff --git a/sys/conf/files b/sys/conf/files index c3852492ea1..20696192979 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $OpenBSD: files,v 1.661 2018/04/20 04:37:21 dlg Exp $ +# $OpenBSD: files,v 1.662 2018/07/02 12:46:20 kettenis Exp $ # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -324,6 +324,10 @@ device com: tty file dev/ic/com.c com & (com | com_cardbus | com_gsc | com_isapnp) needs-flag +# ARM PrimeCell PL011 UART +device pluart: tty +file dev/ic/pluart.c pluart + # PC-like keyboard controller define pckbcslot {[slot = -1]} device pckbc: pckbcslot diff --git a/sys/dev/acpi/files.acpi b/sys/dev/acpi/files.acpi index 0b0d939c705..bd5c3e95268 100644 --- a/sys/dev/acpi/files.acpi +++ b/sys/dev/acpi/files.acpi @@ -1,4 +1,4 @@ -# $OpenBSD: files.acpi,v 1.48 2018/07/02 11:23:19 kettenis Exp $ +# $OpenBSD: files.acpi,v 1.49 2018/07/02 12:46:20 kettenis Exp $ # # Config file and device description for machine-independent ACPI code. # Included by ports that need it. @@ -144,6 +144,10 @@ file dev/acpi/ahci_acpi.c ahci_acpi attach com at acpi with com_acpi file dev/acpi/com_acpi.c com_acpi +# PL011 UART +attach pluart at acpi with pluart_acpi +file dev/acpi/pluart_acpi.c pluart_acpi + # SD Host Controller attach sdhc at acpi with sdhc_acpi file dev/acpi/sdhc_acpi.c sdhc_acpi diff --git a/sys/dev/acpi/pluart_acpi.c b/sys/dev/acpi/pluart_acpi.c new file mode 100644 index 00000000000..79b853ae33f --- /dev/null +++ b/sys/dev/acpi/pluart_acpi.c @@ -0,0 +1,153 @@ +/* $OpenBSD: pluart_acpi.c,v 1.1 2018/07/02 12:46:20 kettenis Exp $ */ +/* + * Copyright (c) 2018 Mark Kettenis + * + * 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/malloc.h> +#include <sys/systm.h> +#include <sys/tty.h> + +#include <dev/acpi/acpireg.h> +#include <dev/acpi/acpivar.h> +#include <dev/acpi/acpidev.h> +#include <dev/acpi/amltypes.h> +#include <dev/acpi/dsdt.h> + +#undef DEVNAME +#include <dev/ic/pluartvar.h> +#include <dev/cons.h> + +struct pluart_acpi_softc { + struct pluart_softc sc; + struct acpi_softc *sc_acpi; + struct aml_node *sc_node; + + bus_addr_t sc_addr; + bus_size_t sc_size; + + int sc_irq; + int sc_irq_flags; + void *sc_ih; +}; + +int pluart_acpi_match(struct device *, void *, void *); +void pluart_acpi_attach(struct device *, struct device *, void *); + +struct cfattach pluart_acpi_ca = { + sizeof(struct pluart_acpi_softc), pluart_acpi_match, pluart_acpi_attach +}; + +const char *pluart_hids[] = { + "AMDI0511", + NULL +}; + +int pluart_acpi_parse_resources(int, union acpi_resource *, void *); +int pluart_acpi_is_console(struct pluart_acpi_softc *); + +int +pluart_acpi_match(struct device *parent, void *match, void *aux) +{ + struct acpi_attach_args *aaa = aux; + struct cfdata *cf = match; + + return acpi_matchhids(aaa, pluart_hids, cf->cf_driver->cd_name); +} + +void +pluart_acpi_attach(struct device *parent, struct device *self, void *aux) +{ + struct acpi_attach_args *aaa = aux; + struct pluart_acpi_softc *sc = (struct pluart_acpi_softc *)self; + struct aml_value res; + + sc->sc_acpi = (struct acpi_softc *)parent; + sc->sc_node = aaa->aaa_node; + printf(" %s", sc->sc_node->name); + + if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, &res)) { + printf(": can't find registers\n"); + return; + } + + aml_parse_resource(&res, pluart_acpi_parse_resources, sc); + printf(" addr 0x%lx/0x%lx", sc->sc_addr, sc->sc_size); + if (sc->sc_addr == 0 || sc->sc_size == 0) { + printf("\n"); + return; + } + + printf(" irq %d", sc->sc_irq); + + sc->sc.sc_iot = aaa->aaa_memt; + if (bus_space_map(sc->sc.sc_iot, sc->sc_addr, sc->sc_size, 0, + &sc->sc.sc_ioh)) { + printf(": can't map registers\n"); + return; + } + + sc->sc_ih = acpi_intr_establish(sc->sc_irq, sc->sc_irq_flags, IPL_TTY, + pluart_intr, sc, sc->sc.sc_dev.dv_xname); + if (sc->sc_ih == NULL) { + printf(": can't establish interrupt\n"); + return; + } + + pluart_attach_common(&sc->sc, pluart_acpi_is_console(sc)); +} + +int +pluart_acpi_parse_resources(int crsidx, union acpi_resource *crs, void *arg) +{ + struct pluart_acpi_softc *sc = arg; + int type = AML_CRSTYPE(crs); + + switch (type) { + case LR_MEM32FIXED: + sc->sc_addr = crs->lr_m32fixed._bas; + sc->sc_size = crs->lr_m32fixed._len; + break; + case LR_EXTIRQ: + sc->sc_irq = crs->lr_extirq.irq[0]; + sc->sc_irq_flags = crs->lr_extirq.flags; + break; + } + + return 0; +} + +int +pluart_acpi_is_console(struct pluart_acpi_softc *sc) +{ + struct acpi_table_header *hdr; + struct acpi_spcr *spcr; + struct acpi_gas *base; + struct acpi_q *entry; + + SIMPLEQ_FOREACH(entry, &sc->sc_acpi->sc_tables, q_next) { + hdr = entry->q_table; + if (strncmp(hdr->signature, SPCR_SIG, + sizeof(hdr->signature)) == 0) { + spcr = entry->q_table; + base = &spcr->base_address; + if (base->address_space_id == GAS_SYSTEM_MEMORY && + base->address == sc->sc_addr) + return 1; + } + } + + return 0; +} diff --git a/sys/dev/fdt/files.fdt b/sys/dev/fdt/files.fdt index 62de92fee6b..372ba82dc2d 100644 --- a/sys/dev/fdt/files.fdt +++ b/sys/dev/fdt/files.fdt @@ -1,4 +1,4 @@ -# $OpenBSD: files.fdt,v 1.64 2018/06/16 14:11:35 kettenis Exp $ +# $OpenBSD: files.fdt,v 1.65 2018/07/02 12:46:20 kettenis Exp $ # # Config file and device description for machine-independent FDT code. # Included by ports that need it. @@ -79,9 +79,8 @@ attach plrtc at fdt file dev/fdt/plrtc.c plrtc # ARM PrimeCell PL011 UART -device pluart -attach pluart at fdt -file dev/fdt/pluart.c pluart +attach pluart at fdt with pluart_fdt +file dev/fdt/pluart_fdt.c pluart_fdt # ARM Power State Coordination Interface device psci diff --git a/sys/dev/fdt/pluart_fdt.c b/sys/dev/fdt/pluart_fdt.c new file mode 100644 index 00000000000..41a6b3de021 --- /dev/null +++ b/sys/dev/fdt/pluart_fdt.c @@ -0,0 +1,80 @@ +/* $OpenBSD: pluart_fdt.c,v 1.1 2018/07/02 12:46:20 kettenis Exp $ */ +/* + * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se> + * Copyright (c) 2005 Dale Rahn <drahn@dalerahn.com> + * + * 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/systm.h> +#include <sys/tty.h> + +#include <machine/bus.h> +#include <machine/fdt.h> + +#include <dev/ic/pluartvar.h> + +#include <dev/ofw/fdt.h> +#include <dev/ofw/openfirm.h> + +int pluart_fdt_match(struct device *, void *, void *); +void pluart_fdt_attach(struct device *, struct device *, void *); + +struct cfattach pluart_fdt_ca = { + sizeof(struct pluart_softc), pluart_fdt_match, pluart_fdt_attach +}; + +void +pluart_init_cons(void) +{ + struct fdt_reg reg; + void *node; + + if ((node = fdt_find_cons("arm,pl011")) == NULL) + return; + if (fdt_get_reg(node, 0, ®)) + return; + + pluartcnattach(fdt_cons_bs_tag, reg.addr, B115200, TTYDEF_CFLAG); +} + +int +pluart_fdt_match(struct device *parent, void *self, void *aux) +{ + struct fdt_attach_args *faa = aux; + + return OF_is_compatible(faa->fa_node, "arm,pl011"); +} + +void +pluart_fdt_attach(struct device *parent, struct device *self, void *aux) +{ + struct fdt_attach_args *faa = aux; + struct pluart_softc *sc = (struct pluart_softc *) self; + + if (faa->fa_nreg < 1) { + printf(": no registers\n"); + return; + } + + sc->sc_irq = arm_intr_establish_fdt(faa->fa_node, IPL_TTY, pluart_intr, + sc, sc->sc_dev.dv_xname); + + 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)) + panic("pluartattach: bus_space_map failed!"); + + pluart_attach_common(sc, stdout_node == faa->fa_node); +} diff --git a/sys/dev/fdt/pluart.c b/sys/dev/ic/pluart.c index 5830da8c834..8f42a3f930c 100644 --- a/sys/dev/fdt/pluart.c +++ b/sys/dev/ic/pluart.c @@ -1,5 +1,4 @@ -/* $OpenBSD: pluart.c,v 1.1 2018/06/05 20:41:19 kettenis Exp $ */ - +/* $OpenBSD: pluart.c,v 1.1 2018/07/02 12:46:20 kettenis Exp $ */ /* * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se> * Copyright (c) 2005 Dale Rahn <drahn@dalerahn.com> @@ -32,17 +31,14 @@ #include <sys/kernel.h> #include <machine/bus.h> -#include <machine/fdt.h> +#include <dev/ic/pluartvar.h> #include <dev/cons.h> #ifdef DDB #include <ddb/db_var.h> #endif -#include <dev/ofw/fdt.h> -#include <dev/ofw/openfirm.h> - #define DEVUNIT(x) (minor(x) & 0x7f) #define DEVCUA(x) (minor(x) & 0x80) @@ -121,53 +117,8 @@ #define UART_DMACR 0x48 /* DMA control register */ #define UART_SPACE 0x100 -struct pluart_softc { - struct device sc_dev; - bus_space_tag_t sc_iot; - bus_space_handle_t sc_ioh; - struct soft_intrhand *sc_si; - void *sc_irq; - struct tty *sc_tty; - struct timeout sc_diag_tmo; - struct timeout sc_dtr_tmo; - int sc_overflows; - int sc_floods; - int sc_errors; - int sc_halt; - u_int16_t sc_ucr1; - u_int16_t sc_ucr2; - u_int16_t sc_ucr3; - u_int16_t sc_ucr4; - u_int8_t sc_hwflags; -#define COM_HW_NOIEN 0x01 -#define COM_HW_FIFO 0x02 -#define COM_HW_SIR 0x20 -#define COM_HW_CONSOLE 0x40 - u_int8_t sc_swflags; -#define COM_SW_SOFTCAR 0x01 -#define COM_SW_CLOCAL 0x02 -#define COM_SW_CRTSCTS 0x04 -#define COM_SW_MDMBUF 0x08 -#define COM_SW_PPS 0x10 - int sc_fifolen; - - u_int8_t sc_initialize; - u_int8_t sc_cua; - u_int16_t *sc_ibuf, *sc_ibufp, *sc_ibufhigh, *sc_ibufend; -#define UART_IBUFSIZE 128 -#define UART_IHIGHWATER 100 - u_int16_t sc_ibufs[2][UART_IBUFSIZE]; - - struct clk *sc_clk; -}; - -int pluartprobe(struct device *parent, void *self, void *aux); -void pluartattach(struct device *parent, struct device *self, void *aux); - void pluartcnprobe(struct consdev *cp); void pluartcninit(struct consdev *cp); -int pluartcnattach(bus_space_tag_t iot, bus_addr_t iobase, int rate, - tcflag_t cflag); int pluartcngetc(dev_t dev); void pluartcnputc(dev_t dev, int c); void pluartcnpollc(dev_t dev, int on); @@ -179,8 +130,6 @@ void pluart_raisedtr(void *arg); void pluart_softint(void *arg); struct pluart_softc *pluart_sc(dev_t dev); -int pluart_intr(void *); - /* XXX - we imitate 'com' serial ports and take over their entry points */ /* XXX: These belong elsewhere */ cdev_decl(com); @@ -190,62 +139,21 @@ struct cfdriver pluart_cd = { NULL, "pluart", DV_TTY }; -struct cfattach pluart_ca = { - sizeof(struct pluart_softc), pluartprobe, pluartattach -}; - bus_space_tag_t pluartconsiot; bus_space_handle_t pluartconsioh; bus_addr_t pluartconsaddr; tcflag_t pluartconscflag = TTYDEF_CFLAG; int pluartdefaultrate = B38400; -void -pluart_init_cons(void) -{ - struct fdt_reg reg; - void *node; - - if ((node = fdt_find_cons("arm,pl011")) == NULL) - return; - if (fdt_get_reg(node, 0, ®)) - return; - - pluartcnattach(fdt_cons_bs_tag, reg.addr, B115200, TTYDEF_CFLAG); -} - -int -pluartprobe(struct device *parent, void *self, void *aux) -{ - struct fdt_attach_args *faa = aux; - - return OF_is_compatible(faa->fa_node, "arm,pl011"); -} - struct cdevsw pluartdev = cdev_tty_init(3/*XXX NUART */ ,pluart); /* 12: serial port */ void -pluartattach(struct device *parent, struct device *self, void *aux) +pluart_attach_common(struct pluart_softc *sc, int console) { - struct fdt_attach_args *faa = aux; - struct pluart_softc *sc = (struct pluart_softc *) self; int maj; - if (faa->fa_nreg < 1) { - printf(": no register data\n"); - return; - } - - sc->sc_irq = arm_intr_establish_fdt(faa->fa_node, IPL_TTY, pluart_intr, - sc, sc->sc_dev.dv_xname); - - 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)) - panic("pluartattach: bus_space_map failed!"); - - if (stdout_node == faa->fa_node) { + if (console) { /* Locate the major number. */ for (maj = 0; maj < nchrdev; maj++) if (cdevsw[maj].d_open == pluartopen) diff --git a/sys/dev/ic/pluartvar.h b/sys/dev/ic/pluartvar.h new file mode 100644 index 00000000000..8fcbed14d5c --- /dev/null +++ b/sys/dev/ic/pluartvar.h @@ -0,0 +1,63 @@ +/* $OpenBSD: pluartvar.h,v 1.1 2018/07/02 12:46:20 kettenis Exp $ */ +/* + * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se> + * Copyright (c) 2005 Dale Rahn <drahn@dalerahn.com> + * + * 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. + */ + +struct pluart_softc { + struct device sc_dev; + bus_space_tag_t sc_iot; + bus_space_handle_t sc_ioh; + struct soft_intrhand *sc_si; + void *sc_irq; + struct tty *sc_tty; + struct timeout sc_diag_tmo; + struct timeout sc_dtr_tmo; + int sc_overflows; + int sc_floods; + int sc_errors; + int sc_halt; + u_int16_t sc_ucr1; + u_int16_t sc_ucr2; + u_int16_t sc_ucr3; + u_int16_t sc_ucr4; + u_int8_t sc_hwflags; +#define COM_HW_NOIEN 0x01 +#define COM_HW_FIFO 0x02 +#define COM_HW_SIR 0x20 +#define COM_HW_CONSOLE 0x40 + u_int8_t sc_swflags; +#define COM_SW_SOFTCAR 0x01 +#define COM_SW_CLOCAL 0x02 +#define COM_SW_CRTSCTS 0x04 +#define COM_SW_MDMBUF 0x08 +#define COM_SW_PPS 0x10 + int sc_fifolen; + + u_int8_t sc_initialize; + u_int8_t sc_cua; + u_int16_t *sc_ibuf, *sc_ibufp, *sc_ibufhigh, *sc_ibufend; +#define UART_IBUFSIZE 128 +#define UART_IHIGHWATER 100 + u_int16_t sc_ibufs[2][UART_IBUFSIZE]; + + struct clk *sc_clk; +}; + +void pluart_attach_common(struct pluart_softc *, int); +int pluart_intr(void *); + +int pluartcnattach(bus_space_tag_t iot, bus_addr_t iobase, int rate, + tcflag_t cflag); |