Re: Writing to a PCI card from the kernel

Kurt Garloff (K.Garloff@ping.de)
Wed, 15 Jul 1998 00:08:00 +0200


On Mon, Jul 13, 1998 at 04:42:16PM -0600, Chris Hirsch wrote:
>
> Hi all...I'm trying to write a module for my linux kernel for a PCI card.
> I'm reading Linux Device Drivers and on page 181 Rubini says that to
> enable the interrupt handler on the parallel port you simply do an outb.
> >From what I understand
> this is *NOT* what you do for a PCI card that is mapped to high memory.
> Can somebody please point me in the write direction on how to enable
> interupts and just how to generally write to the PCI card from a module?

The following applies to 2.1, 2.0 is basically similar, but the syntax
differs somewhat.

1) check for PCI: pci_present ()
2) find your device: struct pci_dev* pdev = pci_find_device (VENDOR_ID, DEV_ID, pdev)
Now you have access to the PCI config space of the device.
Use the info provided in it, especially:
3) get IRQ, IOSpace and MemRegions from the PCI config space
3a) enable busmastering (DMA), if necessary: pci_set_master (pdev)
4) register iospace: check_region (addr, ln); request_region (addr, ln, "NAME")
5) register IRQ handler: request_irq (irq, handler, SA_SHIRQ, "NAME", NULL)
handler is void handler (int irq, void* dev_id, struct pt_regs *regs);
6) You can access your device via IOPorts (inb,inw,inl/outb,outw,outl) or
via the memory mapped space. Use virt_to_bus () and bus_to_virt () to
translate addresses for busmastering memory accesses.
7) It's a good idea to protect your IRQ handler and the driver's data
structures by a spinlock. (2.1 only)
8) Design a user interface for it, if the kernel not already has one for
your device class.

Read kernel sources (drivers, include files) to get an idea on how this is
done in reality. Get PCI doc or read /usr/src/linux/include/linux/pci.h.

-- 
Kurt Garloff, Dortmund 
<K.Garloff@ping.de>
PGP key on http://student.physik.uni-dortmund.de/homepages/garloff

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html