pcidevs updates for the VIA VX900 chipset

2018-07-01 Thread Frederic Cambus
Hi tech@,

Add device IDs of the VIA VX900 chipset.

Attaching a dmesg from my HP t510 Thin Client.

Comments? OK?

Index: sys/dev/pci/pcidevs
===
RCS file: /cvs/src/sys/dev/pci/pcidevs,v
retrieving revision 1.1851
diff -u -p -r1.1851 pcidevs
--- sys/dev/pci/pcidevs 16 Jun 2018 21:29:39 -  1.1851
+++ sys/dev/pci/pcidevs 1 Jul 2018 13:53:17 -
@@ -7427,6 +7427,7 @@ product VIATECH VT3351_HB 0x0351  VT3351 
 product VIATECH VX800_00x0353  VX800 Host
 product VIATECH P4M900 0x0364  P4M900 Host
 product VIATECH VT8371_HB  0x0391  VT8371 Host
+product VIATECH VX900_HB   0x0410  VX900 Host
 product VIATECH VT6415 0x0415  VT6415 IDE
 product VIATECH VT8501 0x0501  VT8501
 product VIATECH VT82C505   0x0505  VT82C505
@@ -7464,6 +7465,7 @@ product VIATECH K8M890_1  0x1336  K8M890 H
 product VIATECH VT3351_2   0x1351  VT3351 Host
 product VIATECH VX800_10x1353  VX800 Host
 product VIATECH P4M900_1   0x1364  P4M900 Host
+product VIATECH VX900_ERR  0x1410  VX900 Error Reporting
 product VIATECH VT82C416   0x1571  VT82C416 IDE
 product VIATECH VT82C1595  0x1595  VT82C1595 PCI
 product VIATECH K8M800_2   0x2204  K8M800 Host
@@ -7480,6 +7482,7 @@ product VIATECH K8M890_2  0x2336  K8M890 H
 product VIATECH VT3351_3   0x2351  VT3351 Host
 product VIATECH VX800_20x2353  VX800 Host
 product VIATECH P4M900_2   0x2364  P4M900 Host
+product VIATECH VX900_00x2410  VX900 Host
 product VIATECH VT8251_PCI 0x287a  VT8251 PCI
 product VIATECH VT8251_PCIE_0  0x287b  VT8251 PCIE
 product VIATECH VT8251_PCIE_1  0x287c  VT8251 PCIE
@@ -7553,6 +7556,7 @@ product VIATECH CHROME9_HC0x3371  Chrome
 product VIATECH VT8237S_ISA0x3372  VT8237S ISA
 product VIATECH VT8237A_PPB_1  0x337a  VT8237A
 product VIATECH VT8237A_PPB_2  0x337b  VT8237A
+product VIATECH VX900_DRAM 0x3410  VX900 DRAM
 product VIATECH VL80x_XHCI 0x3432  VL80x xHCI
 productVIATECH VL805_XHCI  0x3483  VL805 xHCI
 product VIATECH K8M800_4   0x4204  K8M800 Host
@@ -7569,6 +7573,7 @@ product VIATECH K8M890_4  0x4336  K8M890 H
 product VIATECH VT3351_5   0x4351  VT3351 Host
 product VIATECH VX800_40x4353  VX800 Host
 product VIATECH P4M900_4   0x4364  P4M900 Host
+product VIATECH VX900_10x4410  VX900 Host
 product VIATECH K8T890_IOAPIC  0x5238  K8T890 IOAPIC
 product VIATECH PT894_IOAPIC   0x5308  PT894 IOAPIC
 product VIATECH CX700_IDE  0x5324  CX700 IDE
@@ -7579,6 +7584,7 @@ product VIATECH VT3351_IOAPIC 0x5351  VT3
 product VIATECH VX800_IOAPIC   0x5353  VX800 IOAPIC
 product VIATECH P4M900_IOAPIC  0x5364  P4M900 IOAPIC
 product VIATECH VT8237S_SATA   0x5372  VT8237S SATA
+product VIATECH VX900_APIC 0x5410  VX900 APIC
 product VIATECH RHINEII0x6100  RhineII
 product VIATECH VT3351_6   0x6238  VT3351 Host
 product VIATECH VT8251_AHCI0x6287  VT8251 AHCI
@@ -7586,6 +7592,8 @@ product VIATECH K8M890_6  0x6290  K8M890 H
 product VIATECH P4M890_6   0x6327  P4M890 Security
 product VIATECH VX800_60x6353  VX800 Host
 product VIATECH P4M900_6   0x6364  P4M900 Security
+product VIATECH VX900_SCRATCH  0x6410  VX900 Scratch
+product VIATECH CHROME9_HD 0x7122  Chrome9 HD
 product VIATECH K8M800_7   0x7204  K8M800 Host
 product VIATECH VT8378_VGA 0x7205  VT8378 VGA
 product VIATECH PT894_50x7308  PT894 Host
@@ -7601,6 +7609,7 @@ product VIATECH K8HTB_7   0x7282  K8HTB Ho
 product VIATECH CN700_70x7314  CN700 Host
 product VIATECH CX700_70x7324  CX700 Host
 product VIATECH VT3351_7   0x7351  VT3351 Host
+product VIATECH VX900_20x7410  VX900 Host
 product VIATECH VT8231_ISA 0x8231  VT8231 ISA
 product VIATECH VT8231_PWR 0x8235  VT8231 PMG
 product VIATECH VT8363_AGP 0x8305  VT8363 AGP
@@ -7608,6 +7617,7 @@ product VIATECH CX700_ISA 0x8324  CX700 I
 product VIATECH VX800_ISA  0x8353  VX800 ISA
 product VIATECH VT8371_PPB 0x8391  VT8371
 product VIATECH VX855_ISA  0x8409  VX855 ISA
+product VIATECH VX900_ISA  0x8410  VX900 ISA
 product VIATECH VT8501_AGP 0x8501  VT8501 AGP
 product VIATECH VT82C597AGP0x8597  VT82C597 AGP
 product VIATECH VT82C598AGP0x8598  VT82C598 AGP
@@ -7617,6 +7627,7 @@ product VIATECH VX900_IDE 0x9001  VX900 I
 product VIATECH VX800_SDMMC0x9530  VX800 SD/MMC
 product VIATECH VX800_SDIO 0x95d0  VX800 SDIO
 product VIATECH K8T890_PPB_A   0xa238  K8T890
+product VIATECH VX900_PCIE_0   0xa410  VX900 PCIE
 product VIATECH P4M890_PPB_1   0xa327  P4M890
 product VIATECH VX800_A0xa353  VX800 Host
 product VIATECH P4M900_PPB_1   0xa364  P4M900
@@ -7629,15 +7640,19 @@ product VIATECH VT8235_AGP  0xb168  VT8235
 product VIATECH K8HTB_AGP  0xb188  K8HTB AGP
 product VIATECH VT8377_AGP 

Re: cpu.4: VIA C7 CPUs support Enhanced SpeedStep (i386)

2018-07-01 Thread Frederic Cambus
On Tue, Jun 05, 2018 at 10:04:52PM +1000, Jonathan Gray wrote:

> > VIA C7 CPUs support Enhanced SpeedStep, so reflect that in cpu.4.
> > 
> > On the VIA C7 1.5Ghz:
> > 
> > cpu0: VIA Esther processor 1500MHz ("CentaurHauls" 686-class) 1.51 GHz
> > cpu0: 
> > FPU,V86,DE,PSE,TSC,MSR,PAE,MCE,APIC,SEP,MTRR,PGE,CMOV,PAT,CFLUSH,ACPI,MMX,FXSR,SSE,SSE2,TM,PBE,NXE,SSE3,EST,TM2
> > cpu0: Enhanced SpeedStep 1501 MHz: speeds: 1500, 800 MHz
> 
> If you just have the faked high/low table does it really support it
> besides setting the cpuid bit?  No PSS in ACPI?  There is a table
> for a 1.5GHz C7 in i386
> 
> /* 1.50GHz Centaur C7-M 400 MHz FSB */
> static struct est_op C7M_754[] = {
>   ID16(1500, 1004, BUS100),
>   ID16(1400,  988, BUS100),
>   ID16(1000,  940, BUS100),
>   ID16( 800,  844, BUS100),
>   ID16( 600,  844, BUS100),
>   ID16( 400,  844, BUS100),
> };

Sorry for the delay, I wanted to try booting an old VIA C7 motherboard
I have (the dmesg bits from previous mail came from our dmesg archive)
before answering.

I finally was able to find it and do so, and indeed it seems there are
some issues as well:

cpu0: VIA C7 Processor 1000MHz ("CentaurHauls" 686-class) 1 GHz
cpu0: 
FPU,V86,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,CMOV,PAT,CFLUSH,ACPI,MMX,FXSR,SSE,SSE2,TM,PBE,NXE,SSE3,EST,TM2,xTPR

cpu0: unknown Enhanced SpeedStep CPU, msr 0x08100a1308000a13
cpu0: using only highest and lowest power states
cpu0: Enhanced SpeedStep 998 MHz: speeds: 1333, 1067 MHz

I'm not sure it makes sense to spend any time on this, let's forget it.



Re: arm64 acpi(4)

2018-07-01 Thread Mike Larkin
On Sun, Jul 01, 2018 at 06:13:43PM +0200, Mark Kettenis wrote:
> Diff below actually enables acpi(4) on arm64.  Mostly stubs for bits of code 
> that isn't needed on hardware-reduced ACPI.  But the functions have to be 
> there for things to compile.
> 
> This is enough to boot my MACCHIATOBin multi-user.  A few more drivers
> are coming, the crucial bit being pci(4) support.  At that point a
> typical server system should mostly work.
> 
> ok?
> 

reads ok to me, go for it

> 
> Index: arch/arm64/arm64/acpi_machdep.c
> ===
> RCS file: arch/arm64/arm64/acpi_machdep.c
> diff -N arch/arm64/arm64/acpi_machdep.c
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ arch/arm64/arm64/acpi_machdep.c   1 Jul 2018 16:06:03 -
> @@ -0,0 +1,190 @@
> +/*   $OpenBSD$   */
> +/*
> + * 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 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +
> +#include 
> +
> +int  lid_action;
> +
> +int  acpi_fdt_match(struct device *, void *, void *);
> +void acpi_fdt_attach(struct device *, struct device *, void *);
> +void acpi_attach(struct device *, struct device *, void *);
> +
> +struct cfattach acpi_fdt_ca = {
> + sizeof(struct acpi_softc), acpi_fdt_match, acpi_fdt_attach
> +};
> +
> +int
> +acpi_fdt_match(struct device *parent, void *match, void *aux)
> +{
> + struct fdt_attach_args *faa = aux;
> +
> + return OF_is_compatible(faa->fa_node, "openbsd,acpi-5.0");
> +}
> +
> +void
> +acpi_fdt_attach(struct device *parent, struct device *self, void *aux)
> +{
> + struct acpi_softc *sc = (struct acpi_softc *)self;
> + struct fdt_attach_args *faa = aux;
> + bus_dma_tag_t dmat;
> +
> + /* Create coherent DMA tag. */
> + dmat = malloc(sizeof(*sc->sc_dmat), M_DEVBUF, M_WAITOK | M_ZERO);
> + memcpy(dmat, faa->fa_dmat, sizeof(*dmat));
> + dmat->_flags |= BUS_DMA_COHERENT;
> + 
> + sc->sc_memt = faa->fa_iot;
> + sc->sc_dmat = dmat;
> +
> + acpi_attach_common(sc, faa->fa_reg[0].addr);
> +}
> +
> +int
> +acpi_map(paddr_t pa, size_t len, struct acpi_mem_map *handle)
> +{
> + paddr_t pgpa = trunc_page(pa);
> + paddr_t endpa = round_page(pa + len);
> + vaddr_t va = uvm_km_valloc(kernel_map, endpa - pgpa);
> +
> + if (va == 0)
> + return (ENOMEM);
> +
> + handle->baseva = va;
> + handle->va = (u_int8_t *)(va + (pa & PGOFSET));
> + handle->vsize = endpa - pgpa;
> + handle->pa = pa;
> +
> + do {
> + pmap_kenter_pa(va, pgpa, PROT_READ | PROT_WRITE);
> + va += NBPG;
> + pgpa += NBPG;
> + } while (pgpa < endpa);
> +
> + return 0;
> +}
> +
> +void
> +acpi_unmap(struct acpi_mem_map *handle)
> +{
> + pmap_kremove(handle->baseva, handle->vsize);
> + uvm_km_free(kernel_map, handle->baseva, handle->vsize);
> +}
> +
> +int
> +acpi_bus_space_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size,
> +int flags, bus_space_handle_t *bshp)
> +{
> + return bus_space_map(t, addr, size, flags, bshp);
> +}
> +
> +void
> +acpi_bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
> +bus_size_t size)
> +{
> + bus_space_unmap(t, bsh, size);
> +}
> +
> +int
> +acpi_acquire_glk(uint32_t *lock)
> +{
> + /* No global lock. */
> + return 1;
> +}
> +
> +int
> +acpi_release_glk(uint32_t *lock)
> +{
> + /* No global lock. */
> + return 0;
> +}
> +
> +void
> +acpi_attach_machdep(struct acpi_softc *sc)
> +{
> + /* Nothing to do. */
> +}
> +
> +void *
> +acpi_intr_establish(int irq, int flags, int level,
> +int (*func)(void *), void *arg, const char *name)
> +{
> + struct interrupt_controller *ic;
> + uint32_t interrupt[3];
> +
> + extern LIST_HEAD(, interrupt_controller) interrupt_controllers;
> + LIST_FOREACH(ic, _controllers, ic_list) {
> + if (ic->ic_phandle == 1)
> + break;
> + }
> + if (ic == NULL)
> + return NULL;
> +
> + interrupt[0] = 0;
> + interrupt[1] = irq - 32;
> + interrupt[2] = 0x4;
> +
> + return ic->ic_establish(ic->ic_cookie, interrupt, level,
> +  

Re: acpi(4) attach glue for amd64/i386

2018-07-01 Thread Mike Larkin
On Sun, Jul 01, 2018 at 04:59:47PM +0200, Mark Kettenis wrote:
> Diff below moves the attach glue from acpi.c into acpi_machdep.c.
> Gets rid of an #ifdef and helps me avoid an ugly hack on arm64.  There
> is some additional code duplication, but I think this is acceptable.
> 
> ok?
> 

ok mlarkin, and thanks.

> 
> Index: arch/amd64/amd64/acpi_machdep.c
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/acpi_machdep.c,v
> retrieving revision 1.82
> diff -u -p -r1.82 acpi_machdep.c
> --- arch/amd64/amd64/acpi_machdep.c   25 Jun 2018 22:33:24 -  1.82
> +++ arch/amd64/amd64/acpi_machdep.c   1 Jul 2018 14:56:50 -
> @@ -32,11 +32,12 @@
>  
>  #include 
>  
> -#include 
>  #include 
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  
>  #include "isa.h"
>  #include "ioapic.h"
> @@ -63,6 +64,42 @@ extern int acpi_savecpu(void) __returns_
>  #define ACPI_BIOS_RSDP_WINDOW_SIZE0x2
>  
>  u_int8_t *acpi_scan(struct acpi_mem_map *, paddr_t, size_t);
> +
> +int  acpi_match(struct device *, void *, void *);
> +void acpi_attach(struct device *, struct device *, void *);
> +
> +struct cfattach acpi_ca = {
> + sizeof(struct acpi_softc), acpi_match, acpi_attach
> +};
> +
> +int
> +acpi_match(struct device *parent, void *match, void *aux)
> +{
> + struct bios_attach_args *ba = aux;
> + struct cfdata   *cf = match;
> +
> + /* sanity */
> + if (strcmp(ba->ba_name, cf->cf_driver->cd_name))
> + return (0);
> +
> + if (!acpi_probe(parent, cf, ba))
> + return (0);
> +
> + return (1);
> +}
> +
> +void
> +acpi_attach(struct device *parent, struct device *self, void *aux)
> +{
> + struct acpi_softc *sc = (struct acpi_softc *)self;
> + struct bios_attach_args *ba = aux;
> +
> + sc->sc_iot = ba->ba_iot;
> + sc->sc_memt = ba->ba_memt;
> + sc->sc_dmat = _bus_dma_tag;
> +
> + acpi_attach_common(sc, ba->ba_acpipbase);
> +}
>  
>  int
>  acpi_map(paddr_t pa, size_t len, struct acpi_mem_map *handle)
> Index: arch/amd64/conf/files.amd64
> ===
> RCS file: /cvs/src/sys/arch/amd64/conf/files.amd64,v
> retrieving revision 1.95
> diff -u -p -r1.95 files.amd64
> --- arch/amd64/conf/files.amd64   25 Jan 2018 15:06:29 -  1.95
> +++ arch/amd64/conf/files.amd64   1 Jul 2018 14:56:50 -
> @@ -232,6 +232,7 @@ include "dev/gpio/files.gpio"
>  # ACPI
>  #
>  include "dev/acpi/files.acpi"
> +attach   acpi at bios
>  file arch/amd64/amd64/acpi_machdep.c acpi
>  file arch/amd64/amd64/acpi_wakecode.Sacpi & !small_kernel
>  
> Index: arch/i386/conf/files.i386
> ===
> RCS file: /cvs/src/sys/arch/i386/conf/files.i386,v
> retrieving revision 1.237
> diff -u -p -r1.237 files.i386
> --- arch/i386/conf/files.i386 25 Jan 2018 15:06:29 -  1.237
> +++ arch/i386/conf/files.i386 1 Jul 2018 14:56:50 -
> @@ -389,6 +389,7 @@ include "dev/onewire/files.onewire"
>  include "dev/sdmmc/files.sdmmc"
>  
>  include "dev/acpi/files.acpi"
> +attach   acpi at bios
>  file arch/i386/i386/acpi_machdep.c   acpi
>  file arch/i386/i386/acpi_wakecode.S  acpi & !small_kernel
>  
> Index: arch/i386/i386/acpi_machdep.c
> ===
> RCS file: /cvs/src/sys/arch/i386/i386/acpi_machdep.c,v
> retrieving revision 1.66
> diff -u -p -r1.66 acpi_machdep.c
> --- arch/i386/i386/acpi_machdep.c 25 Jun 2018 22:33:24 -  1.66
> +++ arch/i386/i386/acpi_machdep.c 1 Jul 2018 14:56:50 -
> @@ -39,10 +39,11 @@
>  #include 
>  #include 
>  
> -#include 
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  
>  #include "apm.h"
>  #include "isa.h"
> @@ -73,6 +74,42 @@ extern void intr_calculatemasks(void);
>  #define ACPI_BIOS_RSDP_WINDOW_SIZE0x2
>  
>  u_int8_t *acpi_scan(struct acpi_mem_map *, paddr_t, size_t);
> +
> +int  acpi_match(struct device *, void *, void *);
> +void acpi_attach(struct device *, struct device *, void *);
> +
> +struct cfattach acpi_ca = {
> + sizeof(struct acpi_softc), acpi_match, acpi_attach
> +};
> +
> +int
> +acpi_match(struct device *parent, void *match, void *aux)
> +{
> + struct bios_attach_args *ba = aux;
> + struct cfdata   *cf = match;
> +
> + /* sanity */
> + if (strcmp(ba->ba_name, cf->cf_driver->cd_name))
> + return (0);
> +
> + if (!acpi_probe(parent, cf, ba))
> + return (0);
> +
> + return (1);
> +}
> +
> +void
> +acpi_attach(struct device *parent, struct device *self, void *aux)
> +{
> + struct acpi_softc *sc = (struct acpi_softc *)self;
> + struct bios_attach_args *ba = aux;
> +
> + sc->sc_iot = ba->ba_iot;
> + sc->sc_memt = ba->ba_memt;
> + sc->sc_dmat = _bus_dma_tag;
> +
> + acpi_attach_common(sc, 

Re: pluart@acpi

2018-07-01 Thread Mike Larkin
On Sun, Jul 01, 2018 at 04:38:35PM +0200, Mark Kettenis wrote:
> Since the ARM SBSA Generic UART is effectively a PL011 UART, the
> expectation is that most arm64 servers will actually have pluart(4) as
> their serial console instead of com(4).  So we need a glue for
> acpi(4).  This provides that glue and moves the shared code from
> dev/fdt to dev/ic.
> 
> ok?
> 

ok mlarkin.

> P.S. This driver needs some cleanup.  But that should be done separately.
> 

Yeah, you're not kidding there...

> 
> Index: conf/files
> ===
> RCS file: /cvs/src/sys/conf/files,v
> retrieving revision 1.661
> diff -u -p -r1.661 files
> --- conf/files20 Apr 2018 04:37:21 -  1.661
> +++ conf/files1 Jul 2018 14:29:40 -
> @@ -324,6 +324,10 @@ device   com: tty
>  file dev/ic/com.ccom & (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
> Index: dev/acpi/files.acpi
> ===
> RCS file: /cvs/src/sys/dev/acpi/files.acpi,v
> retrieving revision 1.45
> diff -u -p -r1.45 files.acpi
> --- dev/acpi/files.acpi   1 Jul 2018 10:29:30 -   1.45
> +++ dev/acpi/files.acpi   1 Jul 2018 14:29:40 -
> @@ -137,9 +137,17 @@ device   ccpmic
>  attach   ccpmic at i2c
>  file dev/acpi/ccpmic.c   ccpmic
>  
>  # NS16550 compatible UART
>  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
> Index: dev/acpi/pluart_acpi.c
> ===
> RCS file: dev/acpi/pluart_acpi.c
> diff -N dev/acpi/pluart_acpi.c
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ dev/acpi/pluart_acpi.c1 Jul 2018 14:29:40 -
> @@ -0,0 +1,153 @@
> +/*   $OpenBSD$   */
> +/*
> + * 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 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#undef DEVNAME
> +#include 
> +#include 
> +
> +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, )) {
> + printf(": can't find registers\n");
> + return;
> + }
> +
> + aml_parse_resource(, 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) {
> +  

Re: ahci@acpi

2018-07-01 Thread Mike Larkin
On Sun, Jul 01, 2018 at 02:15:04PM +0200, Mark Kettenis wrote:
> Diff below makes it possible to attach ahci(4) at acpi(4) as required by
> arm64 machines like the MACCHIATOBin and Overdrive 1000.
> 
> ok?
> 

ok mlarkin

> 
> Index: dev/acpi/ahci_acpi.c
> ===
> RCS file: dev/acpi/ahci_acpi.c
> diff -N dev/acpi/ahci_acpi.c
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ dev/acpi/ahci_acpi.c  1 Jul 2018 12:13:03 -
> @@ -0,0 +1,145 @@
> +/*   $OpenBSD$   */
> +/*
> + * 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 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#undef DEVNAME
> +#include 
> +#include 
> +
> +struct ahci_acpi_softc {
> + struct ahci_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  ahci_acpi_match(struct device *, void *, void *);
> +void ahci_acpi_attach(struct device *, struct device *, void *);
> +
> +struct cfattach ahci_acpi_ca = {
> + sizeof(struct ahci_acpi_softc), ahci_acpi_match, ahci_acpi_attach
> +};
> +
> +const char *ahci_hids[] = {
> + "AMDI0600",
> + "LNRO001E",
> + NULL
> +};
> +
> +int  ahci_acpi_parse_resources(int, union acpi_resource *, void *);
> +
> +int
> +ahci_acpi_match(struct device *parent, void *match, void *aux)
> +{
> + struct acpi_attach_args *aaa = aux;
> + struct cfdata *cf = match;
> +
> + return acpi_matchhids(aaa, ahci_hids, cf->cf_driver->cd_name);
> +}
> +
> +void
> +ahci_acpi_attach(struct device *parent, struct device *self, void *aux)
> +{
> + struct acpi_attach_args *aaa = aux;
> + struct ahci_acpi_softc *sc = (struct ahci_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, )) {
> + printf(": can't find registers\n");
> + return;
> + }
> +
> + aml_parse_resource(, ahci_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;
> + sc->sc.sc_ios = sc->sc_size;
> + sc->sc.sc_dmat = aaa->aaa_dmat;
> +
> + if (bus_space_map(sc->sc.sc_iot, sc->sc_addr, sc->sc_size, 0,
> + >sc.sc_ioh)) {
> + printf(": can't map registers\n");
> + return;
> + }
> +
> + sc->sc_ih = acpi_intr_establish(sc->sc_irq, sc->sc_irq_flags, IPL_BIO,
> + ahci_intr, sc, sc->sc.sc_dev.dv_xname);
> + if (sc->sc_ih == NULL) {
> + printf(": can't establish interrupt\n");
> + return;
> + }
> +
> + printf(":");
> +
> + if (ahci_attach(>sc) != 0) {
> + /* error printed by ahci_attach */
> + goto irq;
> + }
> +
> + return;
> +
> +irq:
> + return;
> +}
> +
> +int
> +ahci_acpi_parse_resources(int crsidx, union acpi_resource *crs, void *arg)
> +{
> + struct ahci_acpi_softc *sc = arg;
> + int type = AML_CRSTYPE(crs);
> +
> + switch (type) {
> + case LR_MEM32FIXED:
> + /* AHCI registers are specified by the first resource. */
> + if (sc->sc_size == 0) {
> + 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;
> +}
> Index: dev/acpi/files.acpi
> ===
> RCS file: /cvs/src/sys/dev/acpi/files.acpi,v
> retrieving revision 1.45
> diff -u -p -r1.45 files.acpi
> --- dev/acpi/files.acpi   1 Jul 2018 10:29:30 -   

Re: signal to process or posix thread

2018-07-01 Thread Joerg Sonnenberger
On Fri, Jun 29, 2018 at 04:21:17PM +0200, Alexander Bluhm wrote:
> The problem is that POSIX has signals that are sent to processes
> and signals sent to individual threads.  Our kernel does not support
> this properly.

Well, not exactly. POSIX has synchronous and asynchronous signals. I.e.
SIGFPE after a division by zero or SIGBUS/SIGSEGV are typically
synchronous traps thrown by the processing of the instructions of the
current thread. This signals are delivered to the current thread. All
other signals, i.e. those created as side effect of kill(2) are sent to
the process at large. Those signals are handled by the first thread that
doesn't have them masked. In that case, it should be put on the pending
list of the process and any unmasking operation should check the pending
list on whether a signal should be delivered delayed.

Joerg



arm64 acpi(4)

2018-07-01 Thread Mark Kettenis
Diff below actually enables acpi(4) on arm64.  Mostly stubs for bits of code 
that isn't needed on hardware-reduced ACPI.  But the functions have to be there 
for things to compile.

This is enough to boot my MACCHIATOBin multi-user.  A few more drivers
are coming, the crucial bit being pci(4) support.  At that point a
typical server system should mostly work.

ok?


Index: arch/arm64/arm64/acpi_machdep.c
===
RCS file: arch/arm64/arm64/acpi_machdep.c
diff -N arch/arm64/arm64/acpi_machdep.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ arch/arm64/arm64/acpi_machdep.c 1 Jul 2018 16:06:03 -
@@ -0,0 +1,190 @@
+/* $OpenBSD$   */
+/*
+ * 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 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+
+intlid_action;
+
+intacpi_fdt_match(struct device *, void *, void *);
+void   acpi_fdt_attach(struct device *, struct device *, void *);
+void   acpi_attach(struct device *, struct device *, void *);
+
+struct cfattach acpi_fdt_ca = {
+   sizeof(struct acpi_softc), acpi_fdt_match, acpi_fdt_attach
+};
+
+int
+acpi_fdt_match(struct device *parent, void *match, void *aux)
+{
+   struct fdt_attach_args *faa = aux;
+
+   return OF_is_compatible(faa->fa_node, "openbsd,acpi-5.0");
+}
+
+void
+acpi_fdt_attach(struct device *parent, struct device *self, void *aux)
+{
+   struct acpi_softc *sc = (struct acpi_softc *)self;
+   struct fdt_attach_args *faa = aux;
+   bus_dma_tag_t dmat;
+
+   /* Create coherent DMA tag. */
+   dmat = malloc(sizeof(*sc->sc_dmat), M_DEVBUF, M_WAITOK | M_ZERO);
+   memcpy(dmat, faa->fa_dmat, sizeof(*dmat));
+   dmat->_flags |= BUS_DMA_COHERENT;
+   
+   sc->sc_memt = faa->fa_iot;
+   sc->sc_dmat = dmat;
+
+   acpi_attach_common(sc, faa->fa_reg[0].addr);
+}
+
+int
+acpi_map(paddr_t pa, size_t len, struct acpi_mem_map *handle)
+{
+   paddr_t pgpa = trunc_page(pa);
+   paddr_t endpa = round_page(pa + len);
+   vaddr_t va = uvm_km_valloc(kernel_map, endpa - pgpa);
+
+   if (va == 0)
+   return (ENOMEM);
+
+   handle->baseva = va;
+   handle->va = (u_int8_t *)(va + (pa & PGOFSET));
+   handle->vsize = endpa - pgpa;
+   handle->pa = pa;
+
+   do {
+   pmap_kenter_pa(va, pgpa, PROT_READ | PROT_WRITE);
+   va += NBPG;
+   pgpa += NBPG;
+   } while (pgpa < endpa);
+
+   return 0;
+}
+
+void
+acpi_unmap(struct acpi_mem_map *handle)
+{
+   pmap_kremove(handle->baseva, handle->vsize);
+   uvm_km_free(kernel_map, handle->baseva, handle->vsize);
+}
+
+int
+acpi_bus_space_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size,
+int flags, bus_space_handle_t *bshp)
+{
+   return bus_space_map(t, addr, size, flags, bshp);
+}
+
+void
+acpi_bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
+bus_size_t size)
+{
+   bus_space_unmap(t, bsh, size);
+}
+
+int
+acpi_acquire_glk(uint32_t *lock)
+{
+   /* No global lock. */
+   return 1;
+}
+
+int
+acpi_release_glk(uint32_t *lock)
+{
+   /* No global lock. */
+   return 0;
+}
+
+void
+acpi_attach_machdep(struct acpi_softc *sc)
+{
+   /* Nothing to do. */
+}
+
+void *
+acpi_intr_establish(int irq, int flags, int level,
+int (*func)(void *), void *arg, const char *name)
+{
+   struct interrupt_controller *ic;
+   uint32_t interrupt[3];
+
+   extern LIST_HEAD(, interrupt_controller) interrupt_controllers;
+   LIST_FOREACH(ic, _controllers, ic_list) {
+   if (ic->ic_phandle == 1)
+   break;
+   }
+   if (ic == NULL)
+   return NULL;
+
+   interrupt[0] = 0;
+   interrupt[1] = irq - 32;
+   interrupt[2] = 0x4;
+
+   return ic->ic_establish(ic->ic_cookie, interrupt, level,
+   func, arg, (char *)name);
+}
+
+void
+acpi_sleep_clocks(struct acpi_softc *sc, int state)
+{
+}
+
+void
+acpi_resume_clocks(struct acpi_softc *sc)
+{
+}
+
+int
+acpi_sleep_cpu(struct acpi_softc *sc, int state)
+{
+   return 0;
+}
+
+void
+acpi_resume_cpu(struct acpi_softc *sc)
+{
+}
+

Re: acpi(4) attach glue for amd64/i386

2018-07-01 Thread Philip Guenther
On Sun, Jul 1, 2018 at 8:00 AM Mark Kettenis 
wrote:

> Diff below moves the attach glue from acpi.c into acpi_machdep.c.
> Gets rid of an #ifdef and helps me avoid an ugly hack on arm64.  There
> is some additional code duplication, but I think this is acceptable.
>
> ok?
>

Fewer ifdefs, yay.  ok guenther@


acpi(4) attach glue for amd64/i386

2018-07-01 Thread Mark Kettenis
Diff below moves the attach glue from acpi.c into acpi_machdep.c.
Gets rid of an #ifdef and helps me avoid an ugly hack on arm64.  There
is some additional code duplication, but I think this is acceptable.

ok?


Index: arch/amd64/amd64/acpi_machdep.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/acpi_machdep.c,v
retrieving revision 1.82
diff -u -p -r1.82 acpi_machdep.c
--- arch/amd64/amd64/acpi_machdep.c 25 Jun 2018 22:33:24 -  1.82
+++ arch/amd64/amd64/acpi_machdep.c 1 Jul 2018 14:56:50 -
@@ -32,11 +32,12 @@
 
 #include 
 
-#include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "isa.h"
 #include "ioapic.h"
@@ -63,6 +64,42 @@ extern int acpi_savecpu(void) __returns_
 #define ACPI_BIOS_RSDP_WINDOW_SIZE0x2
 
 u_int8_t   *acpi_scan(struct acpi_mem_map *, paddr_t, size_t);
+
+intacpi_match(struct device *, void *, void *);
+void   acpi_attach(struct device *, struct device *, void *);
+
+struct cfattach acpi_ca = {
+   sizeof(struct acpi_softc), acpi_match, acpi_attach
+};
+
+int
+acpi_match(struct device *parent, void *match, void *aux)
+{
+   struct bios_attach_args *ba = aux;
+   struct cfdata   *cf = match;
+
+   /* sanity */
+   if (strcmp(ba->ba_name, cf->cf_driver->cd_name))
+   return (0);
+
+   if (!acpi_probe(parent, cf, ba))
+   return (0);
+
+   return (1);
+}
+
+void
+acpi_attach(struct device *parent, struct device *self, void *aux)
+{
+   struct acpi_softc *sc = (struct acpi_softc *)self;
+   struct bios_attach_args *ba = aux;
+
+   sc->sc_iot = ba->ba_iot;
+   sc->sc_memt = ba->ba_memt;
+   sc->sc_dmat = _bus_dma_tag;
+
+   acpi_attach_common(sc, ba->ba_acpipbase);
+}
 
 int
 acpi_map(paddr_t pa, size_t len, struct acpi_mem_map *handle)
Index: arch/amd64/conf/files.amd64
===
RCS file: /cvs/src/sys/arch/amd64/conf/files.amd64,v
retrieving revision 1.95
diff -u -p -r1.95 files.amd64
--- arch/amd64/conf/files.amd64 25 Jan 2018 15:06:29 -  1.95
+++ arch/amd64/conf/files.amd64 1 Jul 2018 14:56:50 -
@@ -232,6 +232,7 @@ include "dev/gpio/files.gpio"
 # ACPI
 #
 include "dev/acpi/files.acpi"
+attach acpi at bios
 file   arch/amd64/amd64/acpi_machdep.c acpi
 file   arch/amd64/amd64/acpi_wakecode.Sacpi & !small_kernel
 
Index: arch/i386/conf/files.i386
===
RCS file: /cvs/src/sys/arch/i386/conf/files.i386,v
retrieving revision 1.237
diff -u -p -r1.237 files.i386
--- arch/i386/conf/files.i386   25 Jan 2018 15:06:29 -  1.237
+++ arch/i386/conf/files.i386   1 Jul 2018 14:56:50 -
@@ -389,6 +389,7 @@ include "dev/onewire/files.onewire"
 include "dev/sdmmc/files.sdmmc"
 
 include "dev/acpi/files.acpi"
+attach acpi at bios
 file   arch/i386/i386/acpi_machdep.c   acpi
 file   arch/i386/i386/acpi_wakecode.S  acpi & !small_kernel
 
Index: arch/i386/i386/acpi_machdep.c
===
RCS file: /cvs/src/sys/arch/i386/i386/acpi_machdep.c,v
retrieving revision 1.66
diff -u -p -r1.66 acpi_machdep.c
--- arch/i386/i386/acpi_machdep.c   25 Jun 2018 22:33:24 -  1.66
+++ arch/i386/i386/acpi_machdep.c   1 Jul 2018 14:56:50 -
@@ -39,10 +39,11 @@
 #include 
 #include 
 
-#include 
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "apm.h"
 #include "isa.h"
@@ -73,6 +74,42 @@ extern void intr_calculatemasks(void);
 #define ACPI_BIOS_RSDP_WINDOW_SIZE0x2
 
 u_int8_t   *acpi_scan(struct acpi_mem_map *, paddr_t, size_t);
+
+intacpi_match(struct device *, void *, void *);
+void   acpi_attach(struct device *, struct device *, void *);
+
+struct cfattach acpi_ca = {
+   sizeof(struct acpi_softc), acpi_match, acpi_attach
+};
+
+int
+acpi_match(struct device *parent, void *match, void *aux)
+{
+   struct bios_attach_args *ba = aux;
+   struct cfdata   *cf = match;
+
+   /* sanity */
+   if (strcmp(ba->ba_name, cf->cf_driver->cd_name))
+   return (0);
+
+   if (!acpi_probe(parent, cf, ba))
+   return (0);
+
+   return (1);
+}
+
+void
+acpi_attach(struct device *parent, struct device *self, void *aux)
+{
+   struct acpi_softc *sc = (struct acpi_softc *)self;
+   struct bios_attach_args *ba = aux;
+
+   sc->sc_iot = ba->ba_iot;
+   sc->sc_memt = ba->ba_memt;
+   sc->sc_dmat = _bus_dma_tag;
+
+   acpi_attach_common(sc, ba->ba_acpipbase);
+}
 
 int
 acpi_map(paddr_t pa, size_t len, struct acpi_mem_map *handle)
Index: dev/acpi/acpi.c
===
RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
retrieving revision 1.351
diff -u -p -r1.351 acpi.c
--- dev/acpi/acpi.c 1 Jul 2018 10:27:34 -   1.351
+++ 

pluart@acpi

2018-07-01 Thread Mark Kettenis
Since the ARM SBSA Generic UART is effectively a PL011 UART, the
expectation is that most arm64 servers will actually have pluart(4) as
their serial console instead of com(4).  So we need a glue for
acpi(4).  This provides that glue and moves the shared code from
dev/fdt to dev/ic.

ok?

P.S. This driver needs some cleanup.  But that should be done separately.


Index: conf/files
===
RCS file: /cvs/src/sys/conf/files,v
retrieving revision 1.661
diff -u -p -r1.661 files
--- conf/files  20 Apr 2018 04:37:21 -  1.661
+++ conf/files  1 Jul 2018 14:29:40 -
@@ -324,6 +324,10 @@ device com: tty
 file   dev/ic/com.ccom & (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
Index: dev/acpi/files.acpi
===
RCS file: /cvs/src/sys/dev/acpi/files.acpi,v
retrieving revision 1.45
diff -u -p -r1.45 files.acpi
--- dev/acpi/files.acpi 1 Jul 2018 10:29:30 -   1.45
+++ dev/acpi/files.acpi 1 Jul 2018 14:29:40 -
@@ -137,9 +137,17 @@ device ccpmic
 attach ccpmic at i2c
 file   dev/acpi/ccpmic.c   ccpmic
 
 # NS16550 compatible UART
 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
Index: dev/acpi/pluart_acpi.c
===
RCS file: dev/acpi/pluart_acpi.c
diff -N dev/acpi/pluart_acpi.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ dev/acpi/pluart_acpi.c  1 Jul 2018 14:29:40 -
@@ -0,0 +1,153 @@
+/* $OpenBSD$   */
+/*
+ * 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 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#undef DEVNAME
+#include 
+#include 
+
+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;
+};
+
+intpluart_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
+};
+
+intpluart_acpi_parse_resources(int, union acpi_resource *, void *);
+intpluart_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, )) {
+   printf(": can't find registers\n");
+   return;
+   }
+
+   aml_parse_resource(, 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_ioh)) {
+   printf(": can't map registers\n");
+   return;
+   }
+
+   sc->sc_ih = acpi_intr_establish(sc->sc_irq, 

ahci@acpi

2018-07-01 Thread Mark Kettenis
Diff below makes it possible to attach ahci(4) at acpi(4) as required by
arm64 machines like the MACCHIATOBin and Overdrive 1000.

ok?


Index: dev/acpi/ahci_acpi.c
===
RCS file: dev/acpi/ahci_acpi.c
diff -N dev/acpi/ahci_acpi.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ dev/acpi/ahci_acpi.c1 Jul 2018 12:13:03 -
@@ -0,0 +1,145 @@
+/* $OpenBSD$   */
+/*
+ * 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 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#undef DEVNAME
+#include 
+#include 
+
+struct ahci_acpi_softc {
+   struct ahci_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;
+};
+
+intahci_acpi_match(struct device *, void *, void *);
+void   ahci_acpi_attach(struct device *, struct device *, void *);
+
+struct cfattach ahci_acpi_ca = {
+   sizeof(struct ahci_acpi_softc), ahci_acpi_match, ahci_acpi_attach
+};
+
+const char *ahci_hids[] = {
+   "AMDI0600",
+   "LNRO001E",
+   NULL
+};
+
+intahci_acpi_parse_resources(int, union acpi_resource *, void *);
+
+int
+ahci_acpi_match(struct device *parent, void *match, void *aux)
+{
+   struct acpi_attach_args *aaa = aux;
+   struct cfdata *cf = match;
+
+   return acpi_matchhids(aaa, ahci_hids, cf->cf_driver->cd_name);
+}
+
+void
+ahci_acpi_attach(struct device *parent, struct device *self, void *aux)
+{
+   struct acpi_attach_args *aaa = aux;
+   struct ahci_acpi_softc *sc = (struct ahci_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, )) {
+   printf(": can't find registers\n");
+   return;
+   }
+
+   aml_parse_resource(, ahci_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;
+   sc->sc.sc_ios = sc->sc_size;
+   sc->sc.sc_dmat = aaa->aaa_dmat;
+
+   if (bus_space_map(sc->sc.sc_iot, sc->sc_addr, sc->sc_size, 0,
+   >sc.sc_ioh)) {
+   printf(": can't map registers\n");
+   return;
+   }
+
+   sc->sc_ih = acpi_intr_establish(sc->sc_irq, sc->sc_irq_flags, IPL_BIO,
+   ahci_intr, sc, sc->sc.sc_dev.dv_xname);
+   if (sc->sc_ih == NULL) {
+   printf(": can't establish interrupt\n");
+   return;
+   }
+
+   printf(":");
+
+   if (ahci_attach(>sc) != 0) {
+   /* error printed by ahci_attach */
+   goto irq;
+   }
+
+   return;
+
+irq:
+   return;
+}
+
+int
+ahci_acpi_parse_resources(int crsidx, union acpi_resource *crs, void *arg)
+{
+   struct ahci_acpi_softc *sc = arg;
+   int type = AML_CRSTYPE(crs);
+
+   switch (type) {
+   case LR_MEM32FIXED:
+   /* AHCI registers are specified by the first resource. */
+   if (sc->sc_size == 0) {
+   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;
+}
Index: dev/acpi/files.acpi
===
RCS file: /cvs/src/sys/dev/acpi/files.acpi,v
retrieving revision 1.45
diff -u -p -r1.45 files.acpi
--- dev/acpi/files.acpi 1 Jul 2018 10:29:30 -   1.45
+++ dev/acpi/files.acpi 1 Jul 2018 12:13:03 -
@@ -137,6 +137,10 @@ device ccpmic
 attach ccpmic at i2c
 file   dev/acpi/ccpmic.c   ccpmic
 
+# AHCI
+attach ahci at acpi with ahci_acpi
+file   dev/acpi/ahci_acpi.cahci_acpi

Re: signal to process or posix thread

2018-07-01 Thread Martin Pieuchot
On 29/06/18(Fri) 16:21, Alexander Bluhm wrote:
> On Thu, Jun 28, 2018 at 01:54:29PM +0200, Martin Pieuchot wrote:
> > > It may happen that the worker thread is in the signal handler and
> > > also blocks the signals.
> >
> > Are you saying that the worker thread modified its mask itself, via
> > a syscall, or that the kernel changed `p_sigmask'?
> 
> Unless SA_NODEFER is set, the kernel masks signals while the handler
> is running.  This is done here:
> 
> if ((sa->sa_flags & SA_NODEFER) == 0)
> sa->sa_mask |= sigmask(signum);
> ps->ps_catchmask[signum] = sa->sa_mask &~ sigcantmask;
> ...
> atomic_setbits_int(>p_sigmask, ps->ps_catchmask[signum]);
> 
> > >   Then all threads block them and ptsignal()
> > > sends it to the main thread.  In the test program the main thread
> > > blocks them forever and the process gets stuck.
> > 
> > Can you point us to the piece of code containing this logic?  Is it:
> > 
> > * [...].  Otherwise, mark it pending on the
> > * main thread.
> 
> Yes.  All threads mask the signal so it ends pending at the main
> thread.  prsignal() calls ptsignal(ps_mainproc), so this thread is
> used if the TAILQ_FOREACH(q, >ps_threads, p_thr_link) loop finds
> no match.
> 
> > > According to POSIX any thread should process the signal when it
> > > unblocks.
> > 
> > Does that mean we should rather mark the signal pending on the thread
> > will unblock it?  Do we have a way to know that it will unblock it (see
> > my first question)?
> 
> The problem is that POSIX has signals that are sent to processes
> and signals sent to individual threads.  Our kernel does not support
> this properly.
> 
> We can improve the heuristic.  But still we don't know that the
> thread in the signal handler will unblock the signal first.  It is
> the case for the programs in posixtestsuite, so your suggestion
> could work.

You mentioned NetBSD in your previous email, did you look at how they
solve this problem?

>  But I think it is less general than my solution.  Also
> I don't know how to figure out whether a thread is currently
> processing a signal handler.  And still this does not mean it will
> finish and unblock.

Here's an idea:

  We need another field to save which signals are masked because the
thread is currently executing a handler.  Then when a signal is masked,
before looking for a sibling to deliver it, we check if it is masked
because of a signal handler.  If that's the case we know it can be
delivered soon.

> My solution has the drawback that signals sent to the main thread
> may be handled like signals sent to the process.

I'm afraid that your solution goes in the wrong direction.  I think
we have to improve the heuristic.  We have to untangle per-thread and
per-process bits.



Re: errors in usage.c - libusbhid

2018-07-01 Thread Martin Pieuchot
On 30/06/18(Sat) 23:47, David Bern wrote:
> > Note that your diff doesn't apply.  You have tab vs spaces issues.
> Sorry about that, it seems like I need to setup a proper mail-client.
> 
> > I don't understand what you're talking about.  Can you give example of
> > the 3 scenarios you're talking about.
> If you look inside /usr/share/misc/usb_hid_usages you will find it in
> 9 Button, 10 Ordinal, 16 Unicode and 129 Monitor Enumerated Values.
> 
> > There's also a similar fix in NetBSD's tree, did you look at it?
> I took a look now and it enlightened a potential problem.
> 
> NetBSD is using fmtcheck to make sure a "correct" format string is
> used. I could perhaps make an effort on a patch adding that function into
> stdio in OpenBSD,  as that solves uses of %u compatible format strings
> https://man.openbsd.org/NetBSD-7.1/fmtcheck.3

Better fix the current problem without adding a new function.

> I do now also see what your concerns about scanf might of been.
> My proposed patch open up for a two step "attack".
> If a malicious user is able to alter the contents of usb_hid_usages
> and change the name to add something like %s and if a program then
> lets a user specify a name to be used by hid_parse_usage_in_page
> it could then perform a buffer overflow.
> 
> My first solution of using a "static" format-string would not been affected
> by this potential attack or the version using strtonum(). but at the same
> time
> it would not be able to parse the 16 Unicode example.

Is it necessary to parse these examples?  Or maybe we can live with your
strtonum() fix for now.

> One middle way solution could be to write a "scanf" that only handles %u or
> %x
> format strings, in other words a simplified variant of fmtcheck.
> 
> 
> Would really love to get some advice before continuing working on this
> patch.

I don't know.  So unless somebody else gives us some input I'd suggest
we move forward with your safe diff even if it doesn't fix all the
cases.

If it fixes your use case it is already an improvement.