Re: PCI register questions..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 05, 2003 at 11:39:27AM +0100, Jules Bj?rn Colding wrote:
> On Wed, 2003-02-05 at 10:04, Erik Mouw wrote:
> > Don't fiddle with the PCI config space like that. We have the function
> > pci_write_config_byte() and friends for that. If you use those
> > functions, your driver will be portable, so it will work without
> > changing a single line of code the minute you put it in a PowerPC
> > machine. Another advantage is that using the pci_*() functions make
> > your code much more readable.
> 
> I would love to do that, but I need a struct pci_dev before I can use
> pci_write_config_byte() and friends. To find a pci_dev (with
> pci_find_device() I think) I need a vendor and device id. My problem is
> that I don't have these. My device is a CR16MCS9 (see google) which has
> been bolted onto the PCI/ISA bridge. This device reports no vendor or
> device id to the system, well.. maybe it does, but then I can't find it.
> 
> I can therefore not see how I can get a pci_dev pointer and thought that
> my only solution was to write directly to the pci registers. Is there
> another way around this problem ?

Yes. The CR16MCS9 is bolted to the PCI/ISA bridge. In order to fiddle
with it, you need to talk to the bridge. The bridge has a PCI ID, so
you can get the a struct pci_dev. (I suppose your PCI/ISA bridge is
something like the PLX 9080). There are several ways to get a struct
pci_dev, but the preferred way is to use a PCI ID table:


static int __devinit my_init_one (struct pci_dev *pdev, const
		struct pci_device_id *ent)
{
	int rv;

	rv = pci_enable_device(pdev);

	/* all other initialisation, like pci_reserve_regions() */

	return 0;
}


static void __devexit my_remove_one (struct pci_dev *pdev)
{
        pci_release_regions(pdev);
}


const static struct pci_device_id my_pci_tbl[] __devinitdata =
{
        { PCI_VENDOR_ID_MYCARD, PCI_DEVICE_ID_MYCARD, PCI_ANY_ID, PCI_ANY_ID, },
        { 0, }
};
MODULE_DEVICE_TABLE(pci, my_pci_tbl);


static struct pci_driver my_driver = {
        name:           MY_NAME,
        id_table:       my_pci_tbl,
        probe:          my_init_one,
        remove:         my_remove_one,
};


static int __init my_init_module (void)
{
        return  pci_module_init(&my_driver);
}


static void __exit my_exit_module (void)
{
        pci_unregister_driver(&my_driver);      
}


module_init(my_init_module);
module_exit(my_exit_module);


Another way to get a struct pci_dev is pci_find_device(), which can be
called with a NULL parameter to start a new search. Just run "make
psdocs" in your kernel tree, and you'll get
Documentation/DocBook/kernel-api.ps, which documents the Linux PCI
interface (among others).


Erik

-- 
J.A.K. (Erik) Mouw
Email: J.A.K.Mouw@its.tudelft.nl  mouw@nl.linux.org

Attachment: pgp00288.pgp
Description: PGP signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux