Re: [macppc] mpcpcibr buglet

2022-02-02 Thread Mark Kettenis
> Date: Wed, 2 Feb 2022 10:47:59 +
> From: Miod Vallat 
> 
> On PowerMac11,2 systems, the PCIe bus attaches as:
> 
> mpcpcibr0 at mainbus0 pci: u4-pcie
> pci0 at mpcpcibr0 bus 0
> 
> However none of the devices attached to pci0 will appear in pcidump.
> 
> This is caused by an incorrect bus number during attachment of the
> pci(4) subdevice. The following diff queries the `bus-range' property in
> order to use the correct number (and also contains a bunch of whitespace
> and KNF fixes).
> 
> With the diff below applied, the attachment becomes:
> 
> mpcpcibr0 at mainbus0 pci: u4-pcie
> pci0 at mpcpcibr0 bus 10
> 
> and pci0 devices will appear in the pcidump output.

ok kettenis@

> Index: mpcpcibus.c
> ===
> RCS file: /OpenBSD/src/sys/arch/macppc/pci/mpcpcibus.c,v
> retrieving revision 1.47
> diff -u -p -r1.47 mpcpcibus.c
> --- mpcpcibus.c   3 Jun 2015 08:41:43 -   1.47
> +++ mpcpcibus.c   2 Feb 2022 10:40:48 -
> @@ -168,7 +168,7 @@ mpcpcibus_find_ranges_32(struct pcibr_so
>   sc->sc_iobus_space.bus_size = prange[found].size_lo;
>   }
>  
> - /* the mem space ranges 
> + /* the mem space ranges
>* apple openfirmware always puts full
>* addresses in config information,
>* it is not necessary to have correct bus
> @@ -185,12 +185,12 @@ mpcpcibus_find_ranges_32(struct pcibr_so
>   prange[i].size_lo);
>  #endif
>   if (base != 0) {
> - if ((base + size) == prange[i].phys)   
> + if ((base + size) == prange[i].phys)
>   size += prange[i].size_lo;
>   else {
>   base = prange[i].phys;
>   size = prange[i].size_lo;
> - } 
> + }
>   } else {
>   base = prange[i].phys;
>   size = prange[i].size_lo;
> @@ -263,7 +263,7 @@ mpcpcibus_find_ranges_64(struct pcibr_so
>   sc->sc_iobus_space.bus_size = prange[found].size_lo;
>   }
>  
> - /* the mem space ranges 
> + /* the mem space ranges
>* apple openfirmware always puts full
>* addresses in config information,
>* it is not necessary to have correct bus
> @@ -307,7 +307,6 @@ mpcpcibrattach(struct device *parent, st
>   struct confargs *ca = aux;
>   struct pcibr_config *lcp;
>   struct pcibus_attach_args pba;
> - int of_node = 0;
>   char compat[32];
>   u_int32_t addr_offset;
>   u_int32_t data_offset;
> @@ -315,41 +314,39 @@ mpcpcibrattach(struct device *parent, st
>   int len;
>   int rangesize;
>   u_int32_t range_store[32];
> + int busrange[2];
>  
>   if (ca->ca_node == 0) {
>   printf("invalid node on mpcpcibr config\n");
>   return;
>   }
> - len=OF_getprop(ca->ca_node, "name", compat, sizeof (compat));
> + len = OF_getprop(ca->ca_node, "name", compat, sizeof(compat));
>   compat[len] = '\0';
>   if (len > 0)
>   printf(" %s", compat);
>  
> - len=OF_getprop(ca->ca_node, "compatible", compat,
> - sizeof (compat));
> - if (len <= 0 ) {
> - len=OF_getprop(ca->ca_node, "name", compat,
> - sizeof (compat));
> + len = OF_getprop(ca->ca_node, "compatible", compat, sizeof(compat));
> + if (len <= 0) {
> + len = OF_getprop(ca->ca_node, "name", compat, sizeof(compat));
>   if (len <= 0) {
>   printf(" compatible and name not found\n");
>   return;
>   }
> - compat[len] = 0; 
> - if (strcmp (compat, "bandit") != 0) {
> + compat[len] = 0;
> + if (strcmp(compat, "bandit") != 0) {
>   printf(" compatible not found and name %s found\n",
>   compat);
>   return;
>   }
>   }
> - compat[len] = 0; 
> + compat[len] = 0;
>   if ((rangesize = OF_getprop(ca->ca_node, "ranges",
>   range_store, sizeof (range_store))) <= 0) {
>   if (strcmp(compat, "u3-ht") == 0) {
>   range_store[0] = 0xabb10113; /* appl U3; */
> - } else 
> + } else
>   printf("range lookup failed, node %x\n", ca->ca_node);
>   }
> - /* translate byte(s) into item count*/
>  
>   lcp = >pcibr_config;
>  
> @@ -363,16 +360,16 @@ mpcpcibrattach(struct device *parent, st
>   M_DEVBUF, NULL, 0, EX_NOWAIT | EX_FILLED);
>  
>   if (ppc_proc_is_64b)
> - mpcpcibus_find_ranges_64 (sc, range_store, rangesize);
> + mpcpcibus_find_ranges_64(sc, range_store, rangesize);
>   else
> - 

[macppc] mpcpcibr buglet

2022-02-02 Thread Miod Vallat
On PowerMac11,2 systems, the PCIe bus attaches as:

mpcpcibr0 at mainbus0 pci: u4-pcie
pci0 at mpcpcibr0 bus 0

However none of the devices attached to pci0 will appear in pcidump.

This is caused by an incorrect bus number during attachment of the
pci(4) subdevice. The following diff queries the `bus-range' property in
order to use the correct number (and also contains a bunch of whitespace
and KNF fixes).

With the diff below applied, the attachment becomes:

mpcpcibr0 at mainbus0 pci: u4-pcie
pci0 at mpcpcibr0 bus 10

and pci0 devices will appear in the pcidump output.

Index: mpcpcibus.c
===
RCS file: /OpenBSD/src/sys/arch/macppc/pci/mpcpcibus.c,v
retrieving revision 1.47
diff -u -p -r1.47 mpcpcibus.c
--- mpcpcibus.c 3 Jun 2015 08:41:43 -   1.47
+++ mpcpcibus.c 2 Feb 2022 10:40:48 -
@@ -168,7 +168,7 @@ mpcpcibus_find_ranges_32(struct pcibr_so
sc->sc_iobus_space.bus_size = prange[found].size_lo;
}
 
-   /* the mem space ranges 
+   /* the mem space ranges
 * apple openfirmware always puts full
 * addresses in config information,
 * it is not necessary to have correct bus
@@ -185,12 +185,12 @@ mpcpcibus_find_ranges_32(struct pcibr_so
prange[i].size_lo);
 #endif
if (base != 0) {
-   if ((base + size) == prange[i].phys)   
+   if ((base + size) == prange[i].phys)
size += prange[i].size_lo;
else {
base = prange[i].phys;
size = prange[i].size_lo;
-   } 
+   }
} else {
base = prange[i].phys;
size = prange[i].size_lo;
@@ -263,7 +263,7 @@ mpcpcibus_find_ranges_64(struct pcibr_so
sc->sc_iobus_space.bus_size = prange[found].size_lo;
}
 
-   /* the mem space ranges 
+   /* the mem space ranges
 * apple openfirmware always puts full
 * addresses in config information,
 * it is not necessary to have correct bus
@@ -307,7 +307,6 @@ mpcpcibrattach(struct device *parent, st
struct confargs *ca = aux;
struct pcibr_config *lcp;
struct pcibus_attach_args pba;
-   int of_node = 0;
char compat[32];
u_int32_t addr_offset;
u_int32_t data_offset;
@@ -315,41 +314,39 @@ mpcpcibrattach(struct device *parent, st
int len;
int rangesize;
u_int32_t range_store[32];
+   int busrange[2];
 
if (ca->ca_node == 0) {
printf("invalid node on mpcpcibr config\n");
return;
}
-   len=OF_getprop(ca->ca_node, "name", compat, sizeof (compat));
+   len = OF_getprop(ca->ca_node, "name", compat, sizeof(compat));
compat[len] = '\0';
if (len > 0)
printf(" %s", compat);
 
-   len=OF_getprop(ca->ca_node, "compatible", compat,
-   sizeof (compat));
-   if (len <= 0 ) {
-   len=OF_getprop(ca->ca_node, "name", compat,
-   sizeof (compat));
+   len = OF_getprop(ca->ca_node, "compatible", compat, sizeof(compat));
+   if (len <= 0) {
+   len = OF_getprop(ca->ca_node, "name", compat, sizeof(compat));
if (len <= 0) {
printf(" compatible and name not found\n");
return;
}
-   compat[len] = 0; 
-   if (strcmp (compat, "bandit") != 0) {
+   compat[len] = 0;
+   if (strcmp(compat, "bandit") != 0) {
printf(" compatible not found and name %s found\n",
compat);
return;
}
}
-   compat[len] = 0; 
+   compat[len] = 0;
if ((rangesize = OF_getprop(ca->ca_node, "ranges",
range_store, sizeof (range_store))) <= 0) {
if (strcmp(compat, "u3-ht") == 0) {
range_store[0] = 0xabb10113; /* appl U3; */
-   } else 
+   } else
printf("range lookup failed, node %x\n", ca->ca_node);
}
-   /* translate byte(s) into item count*/
 
lcp = >pcibr_config;
 
@@ -363,16 +360,16 @@ mpcpcibrattach(struct device *parent, st
M_DEVBUF, NULL, 0, EX_NOWAIT | EX_FILLED);
 
if (ppc_proc_is_64b)
-   mpcpcibus_find_ranges_64 (sc, range_store, rangesize);
+   mpcpcibus_find_ranges_64(sc, range_store, rangesize);
else
-   mpcpcibus_find_ranges_32 (sc, range_store, rangesize);
+   mpcpcibus_find_ranges_32(sc, range_store, rangesize);
 
addr_offset = 0;