> Date: Thu, 3 May 2018 17:18:56 +0000
> From: Miod Vallat <m...@online.fr>
> 
> > Regarding your diff.  The approach seems reasonable to me.  The magic
> > number in the gscbus.c doesn't fill me with joy.
> > 
> > > +         r[4] = cpu_gethpa(0) | (31 - irqbit);   /* iar */
> > 
> > I realise you're following existing practice, but maybe you could you
> > add a gscbus_reg struct similar to what was used in the asp/lasi/wax
> > code and use that?
> 
> I agree this wouldn't hurt, but then, locore uses hardcoded numbers
> because these offsets don't end up in genassym.cf.
> 
> Oh well, some partial cleanup can't hurt.
> 
> New diff - also, because the interrupt assignments at gsc are actually
> local to gsc interrupt controllers, there is no need to reverse the
> order of cpu_intr_findirq(). The "irq" mention in dmesg is a bit
> misleading, but fixing that would require the print function to be
> passed to pdc_scanbus() and it's a bit out of scope of these changes.

Even better.  Go for it.

> Index: conf/GENERIC
> ===================================================================
> RCS file: /OpenBSD/src/sys/arch/hppa/conf/GENERIC,v
> retrieving revision 1.175
> diff -u -p -r1.175 GENERIC
> --- conf/GENERIC      14 Feb 2018 23:51:49 -0000      1.175
> +++ conf/GENERIC      3 May 2018 17:08:26 -0000
> @@ -46,21 +46,19 @@ uturn0    at mainbus0             # U2/UTurn Runway IO
>  uturn1       at mainbus0
>  astro*       at mainbus0             # Astro memory & I/O controller
>  
> -lasi0        at mainbus0 offset 0x100000 irq 28      # LASI host adapter
> -lasi0        at mainbus0 offset 0xfd00000 irq 28     # LASI on C1[01]0, 
> J2[01]0
> -lasi0        at phantomas0 offset 0xfd00000 irq 28   # LASI on [AB]*
> -lasi0        at uturn? offset 0xfd00000 irq 28       # LASI on [CJ]*
> -lasi1        at mainbus0 offset 0x500000 irq 27      # 712 GIO card
> -asp* at mainbus0 irq 28      # this one comes w/ Viper and LEDs
> -wax* at mainbus0 irq 24      # Wax may host EISA as well
> -wax* at phantomas0 irq 24    # Wax on [AB]*
> -wax* at uturn? irq 24        # Wax on C*
> +lasi0        at mainbus0 offset 0x100000             # LASI host adapter
> +lasi0        at mainbus0 offset 0xfd00000            # LASI on C1[01]0, 
> J2[01]0
> +lasi0        at phantomas0 offset 0xfd00000          # LASI on [AB]*
> +lasi0        at uturn? offset 0xfd00000              # LASI on [CJ]*
> +lasi1        at mainbus0 offset 0x500000             # 712 GIO card
> +asp* at mainbus0             # this one comes w/ Viper and LEDs
> +wax* at mainbus0             # Wax may host EISA as well
> +wax* at phantomas0           # Wax on [AB]*
> +wax* at uturn?               # Wax on C*
>  mongoose* at mainbus0 irq 17 # EISA Bus Adapter (i82350 or TI???)
>  #vmeb*       at mainbus0 irq ?       # VME bus adapter
> -dino0        at phantomas? irq 26    # PCI bus bridge on [AB]*
> -dino1        at phantomas? irq 25
> -dino0        at uturn0 irq 26        # PCI bus bridge on [CJ]*
> -dino1        at uturn1 irq 25
> +dino*        at phantomas?           # PCI bus bridge on [AB]*
> +dino*        at uturn?               # PCI bus bridge on [CJ]*
>  pci* at dino?
>  option       PCIVERBOSE
>  #pckbc0      at dino? irq 9
> @@ -176,12 +174,9 @@ onewire* at uow?
>  udl* at uhub?                # DisplayLink USB displays
>  wsdisplay* at udl?
>  
> -sti0 at mainbus0 irq 11      # [H]CRX-{8,24,48}[Z] graphics
> -sti0 at phantomas0 irq 11    # builtin graphics on BC*
> -sti0 at uturn? irq 11
> -sti1 at mainbus0 irq 12
> -sti1 at phantomas0 irq 12
> -sti1 at uturn? irq 12
> +sti* at mainbus0             # [H]CRX-{8,24,48}[Z] graphics
> +sti* at phantomas0           # builtin graphics on BC*
> +sti* at uturn?
>  sti* at pci?                 # EG-PCI, FX*
>  
>  # internal i/o space
> Index: conf/RAMDISK
> ===================================================================
> RCS file: /OpenBSD/src/sys/arch/hppa/conf/RAMDISK,v
> retrieving revision 1.109
> diff -u -p -r1.109 RAMDISK
> --- conf/RAMDISK      30 Dec 2016 22:36:07 -0000      1.109
> +++ conf/RAMDISK      3 May 2018 17:08:26 -0000
> @@ -48,20 +48,18 @@ uturn0            at mainbus0             # U2/UTurn 
> Runway I
>  uturn1               at mainbus0
>  astro*               at mainbus0             # Astro memory & I/O controller
>  
> -lasi0                at mainbus0 offset 0x100000 irq 28      # LASI host 
> adapter
> -lasi0                at mainbus0 offset 0xfd00000 irq 28     # LASI on 
> C1[01]0, J2[01]0
> -lasi0                at phantomas0 offset 0xfd00000 irq 28   # LASI on [AB]*
> -lasi0                at uturn? offset 0xfd00000 irq 28       # LASI on [CJ]*
> -lasi1                at mainbus0 offset 0x500000 irq 27      # 712 GIO card
> -asp*         at mainbus0 irq 28      # this one comes w/ Viper and LEDs
> -wax*         at mainbus0 irq 24      # Wax may host EISA as well
> -wax*         at phantomas0 irq 24    # Wax on [AB]*
> -wax*         at uturn? irq 24        # Wax on C*
> +lasi0                at mainbus0 offset 0x100000     # LASI host adapter
> +lasi0                at mainbus0 offset 0xfd00000    # LASI on C1[01]0, 
> J2[01]0
> +lasi0                at phantomas0 offset 0xfd00000  # LASI on [AB]*
> +lasi0                at uturn? offset 0xfd00000      # LASI on [CJ]*
> +lasi1                at mainbus0 offset 0x500000     # 712 GIO card
> +asp*         at mainbus0             # this one comes w/ Viper and LEDs
> +wax*         at mainbus0             # Wax may host EISA as well
> +wax*         at phantomas0           # Wax on [AB]*
> +wax*         at uturn?               # Wax on C*
>  mongoose*    at mainbus0 irq 17      # EISA Bus Adapter (i82350 or TI???)
> -dino0                at phantomas? irq 26    # PCI bus bridge on [AB]*
> -dino1                at phantomas? irq 25
> -dino0                at uturn0 irq 26        # PCI bus bridge on [CJ]*
> -dino1                at uturn1 irq 25
> +dino*                at phantomas?           # PCI bus bridge on [AB]*
> +dino*                at uturn0               # PCI bus bridge on [CJ]*
>  pci*         at dino?
>  com1         at dino? irq 11
>  
> @@ -112,12 +110,9 @@ ugl*             at uhub?                # Genesys Logic 
> GL620USB
>  wi*          at uhub?                # WaveLAN IEEE 802.11DS
>  ural*                at uhub?                # Ralink RT2500
>  
> -sti0         at mainbus0 irq 11      # [H]CRX-{8,24,48}[Z] graphics
> -sti0         at phantomas0 irq 11    # builtin graphics on BC*
> -sti0         at uturn? irq 11
> -sti1         at mainbus0 irq 12
> -sti1         at phantomas0 irq 12
> -sti1         at uturn? irq 12
> +sti*         at mainbus0             # [H]CRX-{8,24,48}[Z] graphics
> +sti*         at phantomas0           # builtin graphics on BC*
> +sti*         at uturn?
>  sti*         at pci?                 # EG-PCI, FX*
>  
>  gsc0         at asp?                 # Snakes, old 715, old 725, 735/755
> Index: dev/apic.c
> ===================================================================
> RCS file: /OpenBSD/src/sys/arch/hppa/dev/apic.c,v
> retrieving revision 1.18
> diff -u -p -r1.18 apic.c
> --- dev/apic.c        8 Sep 2015 07:14:04 -0000       1.18
> +++ dev/apic.c        3 May 2018 17:08:26 -0000
> @@ -134,8 +134,10 @@ apic_intr_map(struct pci_attach_args *pa
>           PCI_INTERRUPT_LINE(reg));
>  #endif
>       line = PCI_INTERRUPT_LINE(reg);
> -     if (sc->sc_irq[line] == 0)
> -             sc->sc_irq[line] = cpu_intr_findirq();
> +     if (sc->sc_irq[line] <= 0) {
> +             if ((sc->sc_irq[line] = cpu_intr_findirq()) == -1)
> +                     return 1;
> +     }
>       *ihp = (line << APIC_INT_LINE_SHIFT) | sc->sc_irq[line];
>       return (APIC_INT_IRQ(*ihp) == 0);
>  }
> Index: dev/asp.c
> ===================================================================
> RCS file: /OpenBSD/src/sys/arch/hppa/dev/asp.c,v
> retrieving revision 1.14
> diff -u -p -r1.14 asp.c
> --- dev/asp.c 9 Jun 2005 18:01:36 -0000       1.14
> +++ dev/asp.c 3 May 2018 17:08:26 -0000
> @@ -45,7 +45,6 @@
>  #include <machine/cpufunc.h>
>  
>  #include <hppa/dev/cpudevs.h>
> -#include <hppa/dev/viper.h>
>  
>  #include <hppa/gsc/gscbusvar.h>
>  
> @@ -60,14 +59,9 @@ struct asp_hwr {
>  };
>  
>  struct asp_trs {
> -     u_int32_t asp_irr;
> -     u_int32_t asp_imr;
> -     u_int32_t asp_ipr;
> -     u_int32_t asp_icr;
> -     u_int32_t asp_iar;
> -     u_int32_t asp_resv[3];
> +     struct gscbus_ic asp_ic;
>       u_int8_t  asp_cled;
> -     u_int8_t  asp_resv1[3];
> +     u_int8_t  asp_resv[3];
>       struct {
>               u_int           :20,
>                       asp_spu : 3,    /* SPU ID board jumper */
> @@ -111,14 +105,6 @@ const struct asp_spus_tag {
>       { "#7", 0 }
>  };
>  
> -struct asp_softc {
> -     struct  device sc_dev;
> -     struct gscbus_ic sc_ic;
> -
> -     volatile struct asp_hwr *sc_hw;
> -     volatile struct asp_trs *sc_trs;
> -};
> -
>  #define      ASP_IOMASK      0xfe000000
>  /* ASP "Primary Controller" HPA */
>  #define      ASP_CHPA        0xF0800000
> @@ -126,8 +112,8 @@ struct asp_softc {
>  int  aspmatch(struct device *, void *, void *);
>  void aspattach(struct device *, struct device *, void *);
>  
> -struct cfattach asp_ca = {
> -     sizeof(struct asp_softc), aspmatch, aspattach
> +const struct cfattach asp_ca = {
> +     sizeof(struct device), aspmatch, aspattach
>  };
>  
>  struct cfdriver asp_cd = {
> @@ -156,45 +142,41 @@ aspattach(parent, self, aux)
>       struct device *self;
>       void *aux;
>  {
> -     register struct confargs *ca = aux;
> -     register struct asp_softc *sc = (struct asp_softc *)self;
> +     struct confargs *ca = aux;
> +     volatile struct asp_trs *trs;
> +     volatile struct asp_hwr *hw;
> +     struct gscbus_ic *ic;
>       struct gsc_attach_args ga;
>       bus_space_handle_t ioh;
> -     register u_int32_t irr;
> -     register int s;
> +     int s;
>  
>       if (bus_space_map(ca->ca_iot, ca->ca_hpa, IOMOD_HPASIZE, 0, &ioh)) {
>               printf(": can't map IO space\n");
>               return;
>       }
>  
> -     sc->sc_trs = (struct asp_trs *)ASP_CHPA;
> -     sc->sc_hw = (struct asp_hwr *)ca->ca_hpa;
> +     hw = (struct asp_hwr *)ca->ca_hpa;
> +     trs = (struct asp_trs *)ASP_CHPA;
> +     ic = (struct gscbus_ic *)&trs->asp_ic;
>  
>  #ifdef USELEDS
> -     machine_ledaddr = &sc->sc_trs->asp_cled;
> -     machine_ledword = asp_spus[sc->sc_trs->asp_spu].ledword;
> +     machine_ledaddr = &trs->asp_cled;
> +     machine_ledword = asp_spus[trs->asp_spu].ledword;
>  #endif
>  
>       /* reset ASP */
> -     /* sc->sc_hw->asp_reset = 1; */
> +     /* hw->asp_reset = 1; */
>       /* delay(400000); */
>  
>       s = splhigh();
> -     viper_setintrwnd(1 << ca->ca_irq);
> -
> -     sc->sc_trs->asp_imr = ~0;
> -     irr = sc->sc_trs->asp_irr;
> -     sc->sc_trs->asp_imr = 0;
> +     ic->imr = ~0;
> +     (void)ic->irr;
> +     ic->imr = 0;
>       splx(s);
>  
>       printf (": %s rev %d, lan %d scsi %d\n",
> -         asp_spus[sc->sc_trs->asp_spu].name, sc->sc_hw->asp_version,
> -         sc->sc_trs->asp_lan, sc->sc_trs->asp_scsi);
> -
> -     sc->sc_ic.gsc_type = gsc_asp;
> -     sc->sc_ic.gsc_dv = sc;
> -     sc->sc_ic.gsc_base = sc->sc_trs;
> +         asp_spus[trs->asp_spu].name, hw->asp_version,
> +         trs->asp_lan, trs->asp_scsi);
>  
>       ga.ga_ca = *ca; /* clone from us */
>       ga.ga_dp.dp_bc[0] = ga.ga_dp.dp_bc[1];
> @@ -206,6 +188,7 @@ aspattach(parent, self, aux)
>       ga.ga_dp.dp_mod = 0;
>       ga.ga_hpamask = ASP_IOMASK;
>       ga.ga_name = "gsc";
> -     ga.ga_ic = &sc->sc_ic;
> +     ga.ga_parent = gsc_asp;
> +     ga.ga_ic = ic;
>       config_found(self, &ga, gscprint);
>  }
> Index: dev/dino.c
> ===================================================================
> RCS file: /OpenBSD/src/sys/arch/hppa/dev/dino.c,v
> retrieving revision 1.31
> diff -u -p -r1.31 dino.c
> --- dev/dino.c        29 Mar 2014 18:09:29 -0000      1.31
> +++ dev/dino.c        3 May 2018 17:08:26 -0000
> @@ -394,7 +394,7 @@ dino_intr_string(void *v, pci_intr_handl
>  {
>       static char buf[32];
>  
> -     snprintf(buf, 32, "irq %ld", ih);
> +     snprintf(buf, 32, "dino irq %ld", ih);
>  
>       return (buf);
>  }
> @@ -1681,7 +1681,7 @@ dinoattach(parent, self, aux)
>       volatile struct dino_regs *r;
>       const char *p = NULL;
>       u_int data;
> -     int s;
> +     int s, irqbit;
>  
>       sc->sc_bt = ca->ca_iot;
>       sc->sc_dmat = ca->ca_dmatag;
> @@ -1731,20 +1731,6 @@ dinoattach(parent, self, aux)
>  
>       /* TODO reserve dino's pci space ? */
>  
> -     s = splhigh();
> -     r->imr = ~0;
> -     data = r->irr0;
> -     data = r->irr1;
> -     r->imr = 0;
> -     __asm volatile ("" ::: "memory");
> -     r->icr = 0;
> -     r->iar0 = cpu_gethpa(0) | (31 - ca->ca_irq);
> -     splx(s);
> -
> -     sc->sc_ih = cpu_intr_establish(IPL_NESTED, ca->ca_irq,
> -         dino_intr, (void *)sc->sc_regs, sc->sc_dv.dv_xname);
> -     /* TODO establish the bus error interrupt */
> -
>       sc->sc_ver = ca->ca_type.iodc_revision;
>       switch ((ca->ca_type.iodc_model << 4) |
>           (ca->ca_type.iodc_revision >> 4)) {
> @@ -1774,8 +1760,39 @@ dinoattach(parent, self, aux)
>               break;
>       }
>  
> +     irqbit = cpu_intr_findirq();
> +     if (irqbit >= 0)
> +             printf(" irq %d", irqbit);
> +
>       printf(": %s V%d.%d\n", p, sc->sc_ver >> 4, sc->sc_ver & 0xf);
>  
> +     s = splhigh();
> +     r->imr = ~0;
> +     data = r->irr0;
> +     data = r->irr1;
> +     r->imr = 0;
> +     __asm volatile ("" ::: "memory");
> +     r->icr = 0;
> +     if (irqbit >= 0)
> +             r->iar0 = cpu_gethpa(0) | (31 - irqbit);
> +     splx(s);
> +
> +     if (irqbit < 0)
> +             sc->sc_ih = NULL;
> +     else
> +             sc->sc_ih = cpu_intr_establish(IPL_NESTED, irqbit,
> +                 dino_intr, (void *)sc->sc_regs, sc->sc_dv.dv_xname);
> +     if (sc->sc_ih == NULL) {
> +             printf("%s: can't establish interrupt\n", sc->sc_dv.dv_xname);
> +             return;
> +     }
> +
> +     /* TODO establish the bus error interrupt */
> +
> +     /* scan for ps2 kbd/ms, serial, and flying toasters */
> +     ca->ca_hpamask = -1;
> +     pdc_scanbus(self, ca, MAXMODBUS, 0, 0);
> +
>       sc->sc_iot = dino_iomemt;
>       sc->sc_iot.hbt_cookie = sc;
>       sc->sc_iot.hbt_map = dino_iomap;
> @@ -1788,10 +1805,6 @@ dinoattach(parent, self, aux)
>       sc->sc_pc._cookie = sc;
>       sc->sc_dmatag = dino_dmat;
>       sc->sc_dmatag._cookie = sc;
> -
> -     /* scan for ps2 kbd/ms, serial, and flying toasters */
> -     ca->ca_hpamask = -1;
> -     pdc_scanbus(self, ca, MAXMODBUS, 0, 0);
>  
>       bzero(&pba, sizeof(pba));
>       pba.pba_busname = "pci";
> Index: dev/lasi.c
> ===================================================================
> RCS file: /OpenBSD/src/sys/arch/hppa/dev/lasi.c,v
> retrieving revision 1.22
> diff -u -p -r1.22 lasi.c
> --- dev/lasi.c        15 Sep 2004 20:11:28 -0000      1.22
> +++ dev/lasi.c        3 May 2018 17:08:26 -0000
> @@ -54,27 +54,17 @@ struct lasi_hwr {
>       u_int32_t lasi_arbmask;
>  };
>  
> -struct lasi_trs {
> -     u_int32_t lasi_irr;     /* int requset register */
> -     u_int32_t lasi_imr;     /* int mask register */
> -     u_int32_t lasi_ipr;     /* int pending register */
> -     u_int32_t lasi_icr;     /* int command? register */
> -     u_int32_t lasi_iar;     /* int acquire? register */
> -};
> -
>  struct lasi_softc {
>       struct device sc_dev;
> -     struct gscbus_ic sc_ic;
>  
>       struct lasi_hwr volatile *sc_hw;
> -     struct lasi_trs volatile *sc_trs;
>       struct gsc_attach_args ga;      /* for deferred attach */
>  };
>  
>  int  lasimatch(struct device *, void *, void *);
>  void lasiattach(struct device *, struct device *, void *);
>  
> -struct cfattach lasi_ca = {
> +const struct cfattach lasi_ca = {
>       sizeof(struct lasi_softc), lasimatch, lasiattach
>  };
>  
> @@ -91,8 +81,8 @@ lasimatch(parent, cfdata, aux)   
>       void *cfdata;
>       void *aux;
>  {
> -     register struct confargs *ca = aux;
> -     /* register struct cfdata *cf = cfdata; */
> +     struct confargs *ca = aux;
> +     /* struct cfdata *cf = cfdata; */
>  
>       if (ca->ca_type.iodc_type != HPPA_TYPE_BHA ||
>           ca->ca_type.iodc_sv_model != HPPA_BHA_LASI)
> @@ -109,8 +99,9 @@ lasiattach(parent, self, aux)
>  {
>       struct lasi_softc *sc = (struct lasi_softc *)self;
>       struct confargs *ca = aux;
> +     struct gscbus_ic *ic;
>       bus_space_handle_t ioh, ioh2;
> -     int s, in;
> +     int s;
>  
>       if (bus_space_map(ca->ca_iot, ca->ca_hpa,
>           IOMOD_HPASIZE, 0, &ioh)) {
> @@ -125,8 +116,8 @@ lasiattach(parent, self, aux)
>               return;
>       }
>  
> -     sc->sc_trs = (struct lasi_trs *)ca->ca_hpa;
>       sc->sc_hw = (struct lasi_hwr *)(ca->ca_hpa + 0xc000);
> +     ic = (struct gscbus_ic *)ca->ca_hpa;
>  
>       /* XXX should we reset the chip here? */
>  
> @@ -135,17 +126,13 @@ lasiattach(parent, self, aux)
>  
>       /* interrupts guts */
>       s = splhigh();
> -     sc->sc_trs->lasi_iar = cpu_gethpa(0) | (31 - ca->ca_irq);
> -     sc->sc_trs->lasi_icr = 0;
> -     sc->sc_trs->lasi_imr = ~0U;
> -     in = sc->sc_trs->lasi_irr;
> -     sc->sc_trs->lasi_imr = 0;
> +     ic->iar = 0; /* will be set up by gsc when attaching */
> +     ic->icr = 0;
> +     ic->imr = ~0U;
> +     (void)ic->irr;
> +     ic->imr = 0;
>       splx(s);
>  
> -     sc->sc_ic.gsc_type = gsc_lasi;
> -     sc->sc_ic.gsc_dv = sc;
> -     sc->sc_ic.gsc_base = sc->sc_trs;
> -
>  #ifdef USELEDS
>       /* figure out the leds address */
>       switch (cpu_hvers) {
> @@ -203,6 +190,10 @@ lasiattach(parent, self, aux)
>               sc->ga.ga_dp.dp_bc[5] = sc->ga.ga_dp.dp_mod;
>               sc->ga.ga_dp.dp_mod = 0;
>       }
> +     sc->ga.ga_name = "gsc";
> +     sc->ga.ga_hpamask = LASI_IOMASK;
> +     sc->ga.ga_parent = gsc_lasi;
> +     sc->ga.ga_ic = ic;
>       if (sc->sc_dev.dv_unit)
>               config_defer(self, lasi_gsc_attach);
>       else {
> @@ -221,9 +212,6 @@ lasi_gsc_attach(self)
>  {
>       struct lasi_softc *sc = (struct lasi_softc *)self;
>  
> -     sc->ga.ga_name = "gsc";
> -     sc->ga.ga_hpamask = LASI_IOMASK;
> -     sc->ga.ga_ic = &sc->sc_ic;
>       config_found(self, &sc->ga, gscprint);
>  }
>  
> @@ -231,7 +219,7 @@ void
>  lasi_cold_hook(on)
>       int on;
>  {
> -     register struct lasi_softc *sc = lasi_cd.cd_devs[0];
> +     struct lasi_softc *sc = lasi_cd.cd_devs[0];
>  
>       if (!sc)
>               return;
> Index: dev/wax.c
> ===================================================================
> RCS file: /OpenBSD/src/sys/arch/hppa/dev/wax.c,v
> retrieving revision 1.10
> diff -u -p -r1.10 wax.c
> --- dev/wax.c 8 Nov 2004 20:53:25 -0000       1.10
> +++ dev/wax.c 3 May 2018 17:08:26 -0000
> @@ -40,27 +40,12 @@
>  
>  #define      WAX_IOMASK      0xfff00000
>  
> -struct wax_regs {
> -     u_int32_t wax_irr;      /* int request register */
> -     u_int32_t wax_imr;      /* int mask register */
> -     u_int32_t wax_ipr;      /* int pending register */
> -     u_int32_t wax_icr;      /* int command? register */
> -     u_int32_t wax_iar;      /* int acquire? register */
> -};
> -
> -struct wax_softc {
> -     struct device sc_dv;
> -     struct gscbus_ic sc_ic;
> -
> -     struct wax_regs volatile *sc_regs;
> -};
> -
>  int  waxmatch(struct device *, void *, void *);
>  void waxattach(struct device *, struct device *, void *);
>  void wax_gsc_attach(struct device *);
>  
> -struct cfattach wax_ca = {
> -     sizeof(struct wax_softc), waxmatch, waxattach
> +const struct cfattach wax_ca = {
> +     sizeof(struct device), waxmatch, waxattach
>  };
>  
>  struct cfdriver wax_cd = {
> @@ -91,34 +76,29 @@ waxattach(parent, self, aux)
>       struct device *self;
>       void *aux;
>  {
> -     struct wax_softc *sc = (struct wax_softc *)self;
>       struct confargs *ca = aux;
>       struct gsc_attach_args ga;
> +     struct gscbus_ic *ic;
>       bus_space_handle_t ioh;
> -     int s, in;
> +     int s;
>  
>       if (bus_space_map(ca->ca_iot, ca->ca_hpa, IOMOD_HPASIZE, 0, &ioh)) {
>               printf(": can't map IO space\n");
>               return;
>       }
>  
> -     sc->sc_regs = (struct wax_regs *)ca->ca_hpa;
> -
>       printf("\n");
>  
>       /* interrupts guts */
> +     ic = (struct gscbus_ic *)ca->ca_hpa;
>       s = splhigh();
> -     sc->sc_regs->wax_iar = cpu_gethpa(0) | (31 - ca->ca_irq);
> -     sc->sc_regs->wax_icr = 0;
> -     sc->sc_regs->wax_imr = ~0U;
> -     in = sc->sc_regs->wax_irr;
> -     sc->sc_regs->wax_imr = 0;
> +     ic->iar = 0; /* will be set up by gsc when attaching */
> +     ic->icr = 0;
> +     ic->imr = ~0U;
> +     (void)ic->irr;
> +     ic->imr = 0;
>       splx(s);
>  
> -     sc->sc_ic.gsc_type = gsc_wax;
> -     sc->sc_ic.gsc_dv = sc;
> -     sc->sc_ic.gsc_base = sc->sc_regs;
> -
>       ga.ga_ca = *ca; /* clone from us */
>       if (!strcmp(parent->dv_xname, "mainbus0")) {
>               ga.ga_dp.dp_bc[0] = ga.ga_dp.dp_bc[1];
> @@ -132,6 +112,8 @@ waxattach(parent, self, aux)
>  
>       ga.ga_name = "gsc";
>       ga.ga_hpamask = WAX_IOMASK;
> -     ga.ga_ic = &sc->sc_ic;
> +     ga.ga_parent = gsc_wax;
> +     ga.ga_ic = ic;
> +
>       config_found(self, &ga, gscprint);
>  }
> Index: gsc/gscbus.c
> ===================================================================
> RCS file: /OpenBSD/src/sys/arch/hppa/gsc/gscbus.c,v
> retrieving revision 1.30
> diff -u -p -r1.30 gscbus.c
> --- gsc/gscbus.c      28 Nov 2010 20:09:40 -0000      1.30
> +++ gsc/gscbus.c      3 May 2018 17:08:26 -0000
> @@ -38,13 +38,14 @@
>  #include <machine/iomod.h>
>  #include <machine/autoconf.h>
>  #include <machine/cpufunc.h>
> +#include <hppa/dev/viper.h>
>  
>  #include <hppa/gsc/gscbusvar.h>
>  
>  int  gscmatch(struct device *, void *, void *);
>  void gscattach(struct device *, struct device *, void *);
>  
> -struct cfattach gsc_ca = {
> +const struct cfattach gsc_ca = {
>       sizeof(struct gsc_softc), gscmatch, gscattach
>  };
>  
> @@ -71,18 +72,41 @@ gscattach(parent, self, aux)
>  {
>       struct gsc_softc *sc = (struct gsc_softc *)self;
>       struct gsc_attach_args *ga = aux;
> +     int s, irqbit;
>  
>       sc->sc_iot = ga->ga_iot;
>       sc->sc_ic = ga->ga_ic;
>  
> +     irqbit = cpu_intr_findirq();
> +     if (irqbit >= 0)
> +             printf(" irq %d", irqbit);
> +
>  #ifdef USELEDS
>       if (machine_ledaddr)
>               printf(": %sleds", machine_ledword? "word" : "");
>  #endif
>       printf ("\n");
>  
> -     sc->sc_ih = cpu_intr_establish(IPL_NESTED, ga->ga_irq,
> -         gsc_intr, (void *)sc->sc_ic->gsc_base, sc->sc_dev.dv_xname);
> +     if (irqbit < 0)
> +             sc->sc_ih = NULL;
> +     else
> +             sc->sc_ih = cpu_intr_establish(IPL_NESTED, irqbit,
> +                 gsc_intr, (void *)sc->sc_ic, sc->sc_dev.dv_xname);
> +     if (sc->sc_ih == NULL) {
> +             printf("%s: can't establish interrupt\n", sc->sc_dev.dv_xname);
> +             return;
> +     }
> +
> +     /*
> +      * On ASP, the IAR register is not writable; we need to go through
> +      * the memory controller to achieve proper routing.
> +      */
> +     s = splhigh();
> +     if (ga->ga_parent == gsc_asp)
> +             viper_setintrwnd(1 << irqbit);
> +     else
> +             sc->sc_ic->iar = cpu_gethpa(0) | (31 - irqbit);
> +     splx(s);
>  
>       pdc_scanbus(self, &ga->ga_ca, MAXMODBUS, 0, 0);
>  }
> @@ -108,11 +132,10 @@ gsc_intr_establish(sc, irq, pri, handler
>       void *arg;
>       const char *name;
>  {
> -     volatile u_int32_t *r = sc->sc_ic->gsc_base;
>       void *iv;
>  
>       if ((iv = cpu_intr_map(sc->sc_ih, pri, irq, handler, arg, name)))
> -             r[1] |= (1 << irq);
> +             sc->sc_ic->imr |= (1 << irq);
>       else {
>  #ifdef GSCDEBUG
>               printf("%s: attaching irq %d, already occupied\n",
> @@ -129,9 +152,7 @@ gsc_intr_disestablish(sc, v)
>       void *v;
>  {
>  #if notyet
> -     volatile u_int32_t *r = sc->sc_ic->gsc_base;
> -
> -     r[1] &= ~(1 << irq);
> +     sc->sc_ic->imr &= ~(1 << irq);
>  
>       cpu_intr_unmap(sc->sc_ih, v);
>  #endif
> Index: gsc/gscbusvar.h
> ===================================================================
> RCS file: /OpenBSD/src/sys/arch/hppa/gsc/gscbusvar.h,v
> retrieving revision 1.14
> diff -u -p -r1.14 gscbusvar.h
> --- gsc/gscbusvar.h   28 Nov 2010 20:09:40 -0000      1.14
> +++ gsc/gscbusvar.h   3 May 2018 17:08:26 -0000
> @@ -26,10 +26,16 @@
>   * THE POSSIBILITY OF SUCH DAMAGE.
>   */
>  
> +/*
> + * Layout of the interrupt registers, part of the parent bus.
> + */
>  struct gscbus_ic {
> -     enum {gsc_unknown = 0, gsc_lasi, gsc_wax, gsc_asp} gsc_type;
> -     void *gsc_dv;
> -     volatile void *gsc_base;
> +     volatile u_int32_t irr; /* int request register */
> +     volatile u_int32_t imr; /* int mask register */
> +     volatile u_int32_t ipr; /* int pending register */
> +     volatile u_int32_t icr; /* int control register */
> +     volatile u_int32_t iar; /* int address register */
> +     volatile u_int32_t rsvd[3];
>  };
>  
>  struct gsc_attach_args {
> @@ -43,6 +49,7 @@ struct gsc_attach_args {
>  #define      ga_dmatag       ga_ca.ca_dmatag
>  #define      ga_irq          ga_ca.ca_irq
>  #define      ga_pdc_iodc_read        ga_ca.ca_pdc_iodc_read
> +     enum { gsc_unknown = 0, gsc_asp, gsc_lasi, gsc_wax } ga_parent;
>       struct gscbus_ic *ga_ic;        /* IC pointer */
>  }; 
>  
> Index: hppa/intr.c
> ===================================================================
> RCS file: /OpenBSD/src/sys/arch/hppa/hppa/intr.c,v
> retrieving revision 1.49
> diff -u -p -r1.49 intr.c
> --- hppa/intr.c       13 Sep 2015 14:58:20 -0000      1.49
> +++ hppa/intr.c       3 May 2018 17:08:26 -0000
> @@ -134,6 +134,10 @@ cpu_intr_init(void)
>       ssm(PSL_I, mask);
>  }
>  
> +/*
> + * Find an available, non-shared interrupt bit.
> + * Returns -1 if all interrupt bits are in use.
> + */
>  int
>  cpu_intr_findirq(void)
>  {
> Index: hppa/mainbus.c
> ===================================================================
> RCS file: /OpenBSD/src/sys/arch/hppa/hppa/mainbus.c,v
> retrieving revision 1.87
> diff -u -p -r1.87 mainbus.c
> --- hppa/mainbus.c    13 Sep 2015 11:40:01 -0000      1.87
> +++ hppa/mainbus.c    3 May 2018 17:08:26 -0000
> @@ -1238,7 +1238,7 @@ mbattach(parent, self, aux)
>  }
>  
>  /*
> - * retrive CPU #N HPA value
> + * Retrieve CPU #N HPA value
>   */
>  hppa_hpa_t
>  cpu_gethpa(n)
> 

Reply via email to