Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Jun 2003 16:41:44 -0700
From:      John-Mark Gurney <gurney_j@efn.org>
To:        "M. Warner Losh" <imp@bsdimp.com>, ticso@cicely.de, ticso@cicely12.cicely.de, freebsd-current@freebsd.org, freebsd-sparc64@freebsd.org
Subject:   Re: PCI bus numbering and orphaned devices
Message-ID:  <20030610234144.GA39701@funkthat.com>
In-Reply-To: <20030610230230.GC734@crow.dom2ip.de>
References:  <20030609.224621.71095461.imp@bsdimp.com> <20030610115615.GB10527@cicely12.cicely.de> <20030610121249.GE10527@cicely12.cicely.de> <20030610.082730.102566465.imp@bsdimp.com> <20030610223436.GC37257@funkthat.com> <20030610230230.GC734@crow.dom2ip.de>

next in thread | previous in thread | raw e-mail | index | archive | help

--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Thomas Moestl wrote this message on Wed, Jun 11, 2003 at 01:02 +0200:
> On Tue, 2003/06/10 at 15:34:36 -0700, John-Mark Gurney wrote:
> > 
> > Ok, attached is a patched I tried,
> 
> Hmmm, you seem to have forgotten to actually attach it.

Ok, this time I'll attach it!

> > but sad to say, this doesn't work
> > out to well.  I added a printf before and after the REG statement, and
> > a boot with the kernel give this output:
> > found-> vendor=0x108e, dev=0x5000, revid=0x13
> >         bus=0, slot=1, func=1
> >         class=06-04-00, hdrtype=0x01, mfdev=1
> >         cmdreg=0x0147, statreg=0x02a0, cachelnsz=16 (dwords)
> >         lattimer=0x50 (2400 ns), mingnt=0x02 (500 ns), maxlat=0x00 (0 ns)
> > about to read HEADERTYPE
> > panic: trap: data access error
> >
> > [...]
> > 
> > the last three lines repeate for a while, but this is because of:
> > psycho_read_config(...)
> > [...]
> > 	/*
> > 	 * The psycho bridge does not tolerate accesses to unconfigured PCI
> > 	 * devices' or function's config space, so look up the device in the
> > 	 * firmware device tree first, and if it is not present, return a value
> > 	 * that will make the detection code think that there is no device here.
> > 	 * This is ugly...
> > 	 */
> > 	if (reg == 0 && ofw_pci_find_node(bus, slot, func) == 0)
> > 		return (0xffffffff);
> > 
> > Which obviously will fail if reg != 0 which we try to do when reading
> > the PCIR_HEADERTYPE..
> > 
> > So, the question is, does other arch's do something nasty like this
> > too?  Should I change the check to just do ofw_pci_find_node?
> 
> You could safely (it would just be slow), but that alone would not
> help you, since you would also be ignoring requests to the registers
> you want to read without further hackery. You could, of course, look
> into the device tree to see if there are devices at higher functions,
> that would just make that kludge more ugly than it already is :)

Ok, right now in order to get the machine back up and functional I
did remove the reg == 0, and running scanning all the functions.

> There's a similar problem with hme devices in some Netra models, and
> so far I have just ignored this because of the ugliness involved
> (there were patches floating around at one point, but I did not commit
> them).
> 
> The real fix (and the way I wanted to implement things from the
> beginning) is to write an OFW PCI bus, analogous to the ACPI one. This
> is high on my list, waiting for time to become available :)

Yikes, I just started looking at the acpi code, and there's a lot of
code in it!

> > Is this why pciconf -r is returning 0xffffffff when reading the ebus
> > and firewire parts of the SME2300BGA?  Simply because it isn't in
> > the ofw tree? 
> 
> Could be. We just cannot handle devices without firmware nodes - we
> don't know whether we can safely access them, cannot assign interrupts
> etc.

Ok, the only problem is that is then we have the same problem the ACPI
code does in that hot swapping cards would have a problem.  Since it
appears to me that the OFW tree doesn't get updated upon a swap.  (At
least the usb part of the tree doesn't.)

Does this mean that we should eliminate most of the Sun specific pci
bus drivers in favor of OFW specific ones like ACPI? or?

Thanks, I have plenty of time to hack on this right now, so any pointers
would be useful.

-- 
  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."

--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="pci.patch"

Index: pci.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/pci/pci.c,v
retrieving revision 1.214
diff -u -r1.214 pci.c
--- pci.c	2003/04/16 03:15:08	1.214
+++ pci.c	2003/06/10 21:40:16
@@ -816,25 +816,32 @@
 void
 pci_add_children(device_t dev, int busno, size_t dinfo_size)
 {
+#define REG(n, w)	PCIB_READ_CONFIG(pcib, busno, s, f, n, w)
 	device_t pcib = device_get_parent(dev);
 	struct pci_devinfo *dinfo;
 	int maxslots;
 	int s, f, pcifunchigh;
+	u_int8_t hdrtype;
 
 	KASSERT(dinfo_size >= sizeof(struct pci_devinfo),
 	    ("dinfo_size too small"));
 	maxslots = PCIB_MAXSLOTS(pcib);	
 	for (s = 0; s <= maxslots; s++) {
 		pcifunchigh = 0;
+		f = 0;
+		hdrtype = REG(PCIR_HEADERTYPE, 1);
+		if ((hdrtype & ~PCIM_MFDEV) > 2)
+			continue;
+		if (hdrtype & PCIM_MFDEV)
+			pcifunchigh = PCI_FUNCMAX;
 		for (f = 0; f <= pcifunchigh; f++) {
 			dinfo = pci_read_device(pcib, busno, s, f, dinfo_size);
 			if (dinfo != NULL) {
-				if (dinfo->cfg.mfdev)
-					pcifunchigh = PCI_FUNCMAX;
 				pci_add_child(dev, dinfo);
 			}
 		}
 	}
+#undef REG
 }
 
 void
Index: pci_user.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/pci/pci_user.c,v
retrieving revision 1.9
diff -u -r1.9 pci_user.c
--- pci_user.c	2003/03/03 12:15:44	1.9
+++ pci_user.c	2003/06/10 21:40:16
@@ -176,9 +176,8 @@
 	const char *name;
 	int error;
 
-	if (!(flag & FWRITE))
+	if (!(flag & FWRITE) && cmd == PCIOCWRITE)
 		return EPERM;
-
 
 	switch(cmd) {
 	case PCIOCGETCONF:

--PEIAKu/WMn1b1Hv9--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030610234144.GA39701>