Re: reduce hppa interrupt guts awfulness

2018-05-03 Thread Mark Kettenis
> Date: Thu, 3 May 2018 17:18:56 +
> From: Miod Vallat 
> 
> > 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 -  1.175
> +++ conf/GENERIC  3 May 2018 17:08:26 -
> @@ -46,21 +46,19 @@ uturn0at mainbus0 # U2/UTurn Runway IO
>  uturn1   at mainbus0
>  astro*   at mainbus0 # Astro memory & I/O controller
>  
> -lasi0at mainbus0 offset 0x10 irq 28  # LASI host adapter
> -lasi0at mainbus0 offset 0xfd0 irq 28 # LASI on C1[01]0, 
> J2[01]0
> -lasi0at phantomas0 offset 0xfd0 irq 28   # LASI on [AB]*
> -lasi0at uturn? offset 0xfd0 irq 28   # LASI on [CJ]*
> -lasi1at mainbus0 offset 0x50 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*
> +lasi0at mainbus0 offset 0x10 # LASI host adapter
> +lasi0at mainbus0 offset 0xfd0# LASI on C1[01]0, 
> J2[01]0
> +lasi0at phantomas0 offset 0xfd0  # LASI on [AB]*
> +lasi0at uturn? offset 0xfd0  # LASI on [CJ]*
> +lasi1at mainbus0 offset 0x50 # 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
> -dino0at phantomas? irq 26# PCI bus bridge on [AB]*
> -dino1at phantomas? irq 25
> -dino0at uturn0 irq 26# PCI bus bridge on [CJ]*
> -dino1at 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 -  1.109
> +++ conf/RAMDISK  3 May 2018 17:08:26 -
> @@ -48,20 +48,18 @@ uturn0at mainbus0 # U2/UTurn 
> Runway I
>  uturn1   at mainbus0
>  astro*   at mainbus0 # Astro memory & I/O controller
>  
> -lasi0at mainbus0 offset 0x10 irq 28  # LASI host 
> adapter
> -lasi0at mainbus0 offset 0xfd0 irq 28 # LASI on 
> C1[01]0, J2[01]0
> -lasi0at phantomas0 offset 0xfd0 irq 28   # LASI on [AB]*
> -lasi0at uturn? offset 0xfd0 irq 28   # LASI on [CJ]*
> -lasi1at mainbus0 offset 0x50 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  

Re: reduce hppa interrupt guts awfulness

2018-05-03 Thread Miod Vallat
> 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.

Index: conf/GENERIC
===
RCS file: /OpenBSD/src/sys/arch/hppa/conf/GENERIC,v
retrieving revision 1.175
diff -u -p -r1.175 GENERIC
--- conf/GENERIC14 Feb 2018 23:51:49 -  1.175
+++ conf/GENERIC3 May 2018 17:08:26 -
@@ -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 0x10 irq 28  # LASI host adapter
-lasi0  at mainbus0 offset 0xfd0 irq 28 # LASI on C1[01]0, J2[01]0
-lasi0  at phantomas0 offset 0xfd0 irq 28   # LASI on [AB]*
-lasi0  at uturn? offset 0xfd0 irq 28   # LASI on [CJ]*
-lasi1  at mainbus0 offset 0x50 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 0x10 # LASI host adapter
+lasi0  at mainbus0 offset 0xfd0# LASI on C1[01]0, J2[01]0
+lasi0  at phantomas0 offset 0xfd0  # LASI on [AB]*
+lasi0  at uturn? offset 0xfd0  # LASI on [CJ]*
+lasi1  at mainbus0 offset 0x50 # 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
 #pckbc0at 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/RAMDISK30 Dec 2016 22:36:07 -  1.109
+++ conf/RAMDISK3 May 2018 17:08:26 -
@@ -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 0x10 irq 28  # LASI host adapter
-lasi0  at mainbus0 offset 0xfd0 irq 28 # LASI on C1[01]0, 
J2[01]0
-lasi0  at phantomas0 offset 0xfd0 irq 28   # LASI on [AB]*
-lasi0  at uturn? offset 0xfd0 irq 28   # LASI on [CJ]*
-lasi1  at mainbus0 offset 0x50 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 0x10 # LASI host adapter
+lasi0  at mainbus0 offset 0xfd0# LASI on C1[01]0, J2[01]0
+lasi0  at phantomas0 offset 0xfd0  # LASI on [AB]*
+lasi0  at uturn? offset 0xfd0  # LASI on [CJ]*
+lasi1  at mainbus0 offset 0x50 # 712 GIO card
+asp*   at mainbus0 # this one comes w/ Viper and LEDs
+wax*

Re: reduce hppa interrupt guts awfulness

2018-05-02 Thread Mark Kettenis
> Date: Tue, 1 May 2018 21:22:12 +
> From: Miod Vallat 
> 
> B2000 and C3650 test have been done with sys/dev/ic/com.c downgraded to
> 1.166 in order to avoid freezes (bug resolution ongoing and not related
> to this diff).

So that's why my C3000 didn't come back after a reboot...

The problem is fairly obvious.  The probe for the XR17V35X that was
added in 1.167 reads from a register that is outside the standard
range of 8250 UART registers.  This obviously can't be done, so I've
reverted the com(4)-related bits of that commit.

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?

Wither way, ok kettenis@

> $ cat levandes.vari
> 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 -  1.175
> +++ conf/GENERIC  1 May 2018 20:03:14 -
> @@ -46,21 +46,19 @@ uturn0at mainbus0 # U2/UTurn Runway IO
>  uturn1   at mainbus0
>  astro*   at mainbus0 # Astro memory & I/O controller
>  
> -lasi0at mainbus0 offset 0x10 irq 28  # LASI host adapter
> -lasi0at mainbus0 offset 0xfd0 irq 28 # LASI on C1[01]0, 
> J2[01]0
> -lasi0at phantomas0 offset 0xfd0 irq 28   # LASI on [AB]*
> -lasi0at uturn? offset 0xfd0 irq 28   # LASI on [CJ]*
> -lasi1at mainbus0 offset 0x50 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*
> +lasi0at mainbus0 offset 0x10 # LASI host adapter
> +lasi0at mainbus0 offset 0xfd0# LASI on C1[01]0, 
> J2[01]0
> +lasi0at phantomas0 offset 0xfd0  # LASI on [AB]*
> +lasi0at uturn? offset 0xfd0  # LASI on [CJ]*
> +lasi1at mainbus0 offset 0x50 # 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
> -dino0at phantomas? irq 26# PCI bus bridge on [AB]*
> -dino1at phantomas? irq 25
> -dino0at uturn0 irq 26# PCI bus bridge on [CJ]*
> -dino1at 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 -  1.109
> +++ conf/RAMDISK  1 May 2018 20:03:14 -
> @@ -48,20 +48,18 @@ uturn0at mainbus0 # U2/UTurn 
> Runway I
>  uturn1   at mainbus0
>  astro*   at mainbus0 # Astro memory & I/O controller
>  
> -lasi0at mainbus0 offset 0x10 irq 28  # LASI host 
> adapter
> -lasi0at mainbus0 offset 0xfd0 irq 28 # LASI on 
> C1[01]0, J2[01]0
> -lasi0at phantomas0 offset 0xfd0 irq 28   # LASI on [AB]*
> -lasi0at uturn? offset 0xfd0 irq 28   # LASI on [CJ]*
> -lasi1at mainbus0 offset 0x50 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*
> +lasi0at mainbus0 offset 0x10 # LASI host 

reduce hppa interrupt guts awfulness

2018-05-01 Thread Miod Vallat
[this is long, and hppa-specific, feel free to ignore if you don't care
 about OpenBSD/hppa. Noone does anyway nowadays]

At the beginning of the hppa port, no interrupts were shared - the
processor allows for 32 interrupt sources and the existing designs made
sure to allocate distinct interrupts to every device.

Every device, but the PS/2 keyboard and mouse controller. So mickey
added a kluge about 15 years ago for them when I wrote the keyboard
controller driver. [Yes, really 15 years ago now... time flies]

And then the port grew PCI bus support, where interrupts have to be
shareable, by design. So the interrupt code got some form of shared
interrupts, but, well, the interrupt handling code is definitely not for
the faint of heart. Yet it works... to some extent. This mostly involves
magic, and the ability to understand locore0.s.

Because most of the native hppa drivers have been designed with
exclusive interrupts in mind, the hppa kernel configuration has many
hardwired interrupt vector lines (`irq' locators).

This is the reason why you have distinct foo0 and foo1 lines in the
kernel configuration, even for devices which driver do not use
interrupts at all, such as sti(4).

While working on ``card-mode'' dino(4) support [coming soon], I ended up
with having more than one dino(4) attachment to the same parent. To my
surprise, both were using the same interrupt, which - in the current
state of the interrupt handling code, which I won't touch without a
ten-feet pole - meant interrupts from the first device were completely
ignored, because the second one would happily overwrite all the relevant
interrupt structures for that interrupt bit.

This happens, because of this in mbsubmatch() in
sys/arch/hppa/hppa/mainbus.c:

int
mbsubmatch(parent, match, aux)
struct device *parent;
void *match, *aux;
{
[..]
if ((ret = (*cf->cf_attach->ca_match)(parent, match, aux)))
ca->ca_irq = cf->hppacf_irq;

return ret;
}

This means that "everytime a kernel configuration line matches, we pick
its irq value". And while many devices have stricter checks based on
their physical addresses, PCI bridges such as dino(4) don't.

So, with a kernel configuration having
dino0   at phantomas? irq 26# PCI bus bridge on [AB]*
dino1   at phantomas? irq 25
both lines would match, and both dino controllers would end up using -
but not sharing! - irq 25.

This was not noticed because systems with two dino attachments AT THE
SAME PARENT do not exist in their DEFAULT configuration.

However, adding support for cardmode dino changes the rules. And one can
end up with THREE dino controllers although the kernel only allows for
dino0 and dino1.

The only correct way to address this is to relax this fixed irq
assignments and let the kernel pick unused interrupt vectors. In fact,
this logic was already in use on higher-end elroy(4) systems.

The following diff does:
- dynamic allocation of interrupts for dino(4) and gsc(4).
- only mention irq locators for devices which use interrupts.
- for gsc(4), this actually postpones interrupt allocation until gsc(4)
  attaches, so asp(4)/lasi(4)/wax(4) won't route the interrupt yet, but
  the gsc(4) child will take care of this.
- because of hardwired interrupt line assignment on the pre-PCI systems,
  the logic looking for a free interrupt pin looks from 31 to 0, while
  it used to search in the opposite order. This WILL affect all elroy
  systems (C3xxx, J) but shouldn't have any noticeable effect. Even
  though gsckbc will pick interrupt 26, systems with gsckbc will have
  the asp/lasi/wax controller attaching early enough to leave irq 26
  available by the time gsckbc attacheѕ.
- remove the irq locator for the drivers which do not need a fixed
  assignment. siop and moongoose could benefit from this but don't work
  at the moment so this is left as an exercize to future kernel hackers.
  A side effect from this is that we do not need multiple sti(4)
  attachment lines, so PCI sti(4) devices will now attach as sti0 rather
  than sti2.

With this diff, multiple dino(4) devices attached to the same parent
will use different interrupt sources, and more than two dino(4) devices
can attach.

Tested on 715/75 (old-gen using asp), 715/100/XC (new-gen using lasi),
B132L+, B180L, C240, B2000, C3650.

B2000 and C3650 test have been done with sys/dev/ic/com.c downgraded to
1.166 in order to avoid freezes (bug resolution ongoing and not related
to this diff).

715 and B1xx tests have been done with sys/dev/pckbc/pckbd.c downgraded
to 1.43 (bug resolution ongoing and not related to this diff).

$ cat levandes.vari
Index: conf/GENERIC
===
RCS file: /OpenBSD/src/sys/arch/hppa/conf/GENERIC,v
retrieving revision 1.175
diff -u -p -r1.175 GENERIC
--- conf/GENERIC14 Feb 2018 23:51:49 -