linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Re: HELP: Power Mac G3 PCI Strangeness in 2.2 and 2.3
@ 2000-03-05 21:30 Grant Erickson
  2000-03-06 11:04 ` Geert Uytterhoeven
  0 siblings, 1 reply; 12+ messages in thread
From: Grant Erickson @ 2000-03-05 21:30 UTC (permalink / raw)
  To: Ani Joshi; +Cc: linuxppc-dev


On 3/3/2000 7:39 PM, Ani Joshi wrote:
>On Fri, 3 Mar 2000, Grant Erickson wrote:
>
>>
>>         for (i = 0; i < 10000000; i++) {
>>                 pci_read_config_word(dp, PCI_VENDOR_ID, &data);
>>                 if (data != 0xFFFF)
>>                         break;
>>                 pci_read_config_word(dp, PCI_DEVICE_ID, &data);
>>                 if (data != 0x0000)
>>                         break;
>>         }
>>
>>         for (i = 0; i < 100000000; i++)
>>                 readl(chip);
>
>	why do you do these loops 100000000 times?

So I can  capture traces on the logic analyzer. Sure, I could just
trigger on a one-time event, but this allows me to do an on-the-fly
capture and get some data.

>> 	if (readl(chip) != 0x00000103)
>> 		printk("Bad Chip ID!\n");
>
>	have you tried printking readl(chip)?  what you're expeciting it
>to be may not be correct or you may have to use a slightly different load
>instruction.  btw, you can use pci_resource_{start,end,len}(pdev, res)
>instead of computing length and all.

Yes. I actually ended up figuring all this out not long after I sent out
the e-mail on Friday.

As reported earlier, after instrumenting the PowerPC machine's PCI bus
with a logic analyzer and running a series of tests, I noticed the
following things:

        1) PCI configuration accesses function normally and within spec
           as evidenced by both correct software operation and waveform
           analysis on the logic analyzer.

        2) With the chip's memory space enable bit activated, read
           accesses to the Chip ID register failed to generate any
           PCI bus traffic of any sort and most definitely resulted
           in failed software operation.

After modifying the Linux kernel to accept PCI devices with the invalid
vendor/device ID combination of 0xffff/0x0000, I noticed something odd
about the way the system PROM (and to a lesser extent Linux) configured
the chip's base addresses. Looking at a number of other devices in the
system:

        grant@marathon% cat /proc/iomem
        81800000-8180001f : PCI device 1022:2000 AMD Lance Ethernet
        81900000-819fffff : PCI device 1022:2000 AMD Lance Ethernet
        82000000-82ffffff : PCI device 1002:4754 ATI Mach 128
        f3000000-f307ffff : PCI device 106b:0010 Apple Heathrow I/O
        fffc0000-ffffffff : PCI device ffff:0000 ???

Clue 1: The address range programmed for the chip looks suspiciously like
the state it might be left in after determining how much address space it
needs.

Before Linux does this address space sizing, it saves the base address.
In the case of my chip, it would have read "0x0" since nothing was
programmed there previously. If Linux does find 0x0, it just leaves the
result of the address sizing there and moves on.

So, that led me to wonder where the addresses in the other devices were
coming from...

I found that even before Linux executes a single line of code, all the
other devices above have valid addresses programmed into their base
address registers. Who's doing this?

I believe that the Open Firmware PROM in the PowerPC system probes all
PCI devices in the system at power up. It then assigns valid base
addresses to those devices with VALID vendor and device IDs.

Because my chip uses an invalid vendor ID of 0xFFFF, Open Firmware must
just ignore it and never programs in a valid base address! Therefore,
when we go and try to access the chip at 0xFFFC0000 (which is outside the
valid PCI address space on PReP/CHRP/PowerMac systems?) we're off probing
never-never land. The PCI controller never assumes the transaction!

So, if I fixup the chip's base address register to something like
0x83000000 beforehand, everything works fine! The problem is that I'm not
sure I can unilaterally guarantee 0x83000000 will be available every time
as I don't know the boot ROM's mapping strategy.

 Grant Erickson                       University of Minnesota Alumni
  o mail:grant@borg.umn.edu                               1996 BSEE
  o http://www.tc.umn.edu/~erick205                       1998 MSEE


** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 12+ messages in thread
* HELP: Power Mac G3 PCI Strangeness in 2.2 and 2.3
@ 2000-03-04  1:44 Grant Erickson
  0 siblings, 0 replies; 12+ messages in thread
From: Grant Erickson @ 2000-03-04  1:44 UTC (permalink / raw)
  To: linuxppc-dev


I am working on a driver for a really simple, but custom, PCI chip
installed into one of the slots on my Power Macintosh G3 which is giving
me no end to troubles. The driver and the card work fine in a passel of
i386-based Linux machines (w/ the Linux PCI driver code modified to detect
the odd 0xFFFF/0x0000 VID/DID combo).

With this chip, I can read, modify and write the PCI configuration
register on both a Power Mac and on an i386 machine. A sample dump of the
PCI registers at the time my driver is loaded:

-------------------------------------------------
Off.  PCI Register Name                Value
----  -------------------------------- ----------
0x00  Vendor ID                        0x    ffff
0x02  Device ID                        0x       0
0x04  Command                          0x       2
0x06  Status                           0x     280
0x08  Revision ID                      0x       0
0x09  Program Interface                0x       0
0x0a  Device Class                     0x       0
0x0c  Cache Line Size                  0x       0
0x0d  Primary Latency Timer            0x       0
0x0e  Header Type                      0x       0
0x0f  Built-in Self Test               0x       0
0x10  Base Address 0                   0xfffc0000
0x14  Base Address 1                   0x       0
0x18  Base Address 2                   0x       0
0x1c  Base Address 3                   0x       0
0x20  Base Address 4                   0x       0
0x24  Base Address 5                   0x       0
0x28  Cardbus CIS Pointer              0x       0
0x2c  Subsystem Vendor ID              0x       0
0x2e  Subsystem ID                     0x       0
0x30  Expansion ROM Address            0x       0
0x3c  Interrupt Line                   0x       0
0x3d  Interrupt Pin                    0x       0
0x3e  Minimum Grant                    0x       0
0x3f  Maximum Latency                  0x       0

>From /proc/pci:

  Bus  0, device  20, function  0:
    Class 0000: PCI device ffff:0000 (rev 0).
      Non-prefetchable 32 bit memory at 0xfffc0000 [0xffffffff].

However, once I enable memory space access, request a memory region, and
remap the address, I fail to get the correct first base register from the
device (should be 0x00000103)

The output from my test code:

Found: Bus 0, Slot 20, Function 0, Vendor 0xffff, Device 0x0
PCI Base 0 addr = 0xfffc0000
resource[0].start = 0xfffc0000
Banging on Vendor and Device IDs...
Vendor and Device IDs match!
Chip remapped @ 0xc39dd000
Banging on chip ID...
Chip ID: 0x5504c00f @ 0xc39dd000
Bad chip ID!

If I hook things up to a logic analyzer I can see the VID/DID loop
working; however, once I map in memory access space, nothing goes out on
the bus.

Looking at other PCI devices in the system and the remapped address,
things look suspect. However, after looking at other drivers, I don't see
what I'm missing. Any certain gotchas I should look for?

A brief summary of my code:

{
        int i;
        struct pci_dev *dp;
        u_short data;
        unsigned long addr, res_start, res_size;
        struct resource *rp;
        unsigned long chip;

        dp = pci_find_device(0xFFFF, 0x0000, NULL);

        if (dp == NULL)
                return (-1);

        rp = &dp->resource[0];
        if (rp->flags & IORESOURCE_IO)
                rp = &dp->resource[1];
        addr = rp->start;

        if (!addr)
                return (-EFAULT);

        res_start = rp->start;
        res_size = rp->end - rp->start + 1;

        if (!request_mem_region(res_start, res_size, "chip")) {
                return (-ENOMEM);
        }

        for (i = 0; i < 10000000; i++) {
                pci_read_config_word(dp, PCI_VENDOR_ID, &data);
                if (data != 0xFFFF)
                        break;
                pci_read_config_word(dp, PCI_DEVICE_ID, &data);
                if (data != 0x0000)
                        break;
        }

        pci_read_config_word(dp, PCI_COMMAND, &data);
        if (!(data & PCI_COMMAND_MEMORY)) {
                data |= PCI_COMMAND_MEMORY;
                pci_write_config_word(dp, PCI_COMMAND, data);
        }

        chip = (unsigned long)ioremap(res_start, res_size);

        for (i = 0; i < 100000000; i++)
                readl(chip);

	if (readl(chip) != 0x00000103)
		printk("Bad Chip ID!\n");

        release_mem_region(res_start, res_size);

        return (-1);
}

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2000-03-09 12:52 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-03-05 21:30 HELP: Power Mac G3 PCI Strangeness in 2.2 and 2.3 Grant Erickson
2000-03-06 11:04 ` Geert Uytterhoeven
2000-03-07 20:40   ` Grabbing an Interrupt for a Brain-dead PCI Device Grant Erickson
2000-03-07 21:00     ` Geert Uytterhoeven
2000-03-07 22:00     ` Michel Lanners
2000-03-08  8:31       ` Geert Uytterhoeven
2000-03-08 14:15         ` Matt Porter
2000-03-08 18:47       ` Grant Erickson
2000-03-08 19:12         ` Geert Uytterhoeven
2000-03-09  6:58           ` Michel Lanners
2000-03-09 12:52             ` Gabriel Paubert
  -- strict thread matches above, loose matches on Subject: below --
2000-03-04  1:44 HELP: Power Mac G3 PCI Strangeness in 2.2 and 2.3 Grant Erickson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).