public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Gerd Knorr <kraxel@bytesex.org>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Martin Mares <mj@ucw.cz>, Kernel List <linux-kernel@vger.kernel.org>
Subject: Re: ignore pci devices?
Date: Wed, 11 Sep 2002 14:20:48 +0200	[thread overview]
Message-ID: <20020911122048.GA6863@bytesex.org> (raw)
In-Reply-To: <1031688912.31787.129.camel@irongate.swansea.linux.org.uk>

On Tue, Sep 10, 2002 at 09:15:12PM +0100, Alan Cox wrote:
> On Tue, 2002-09-10 at 19:41, Martin Mares wrote:
> > > pci_driver has no implicit ordering.
> > 
> > Agreed, but I meant inserting it as a module before the other
> > modules.
> 
> Which breaks the moment it meets a hotplug system

Neverless this works fine in the non-hotplugging modular driver case,
i.e. it can be used to fix that particular bt878 card issue.  Might also
be useful for testing ressource allocation error paths of PCI drivers.

  Gerd

==============================[ cut here ]==============================
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/kernel.h>

MODULE_DESCRIPTION("reserve pci card ressources to make device drivers *not* touch the card");
MODULE_AUTHOR("Gerd Knorr");
MODULE_LICENSE("GPL");

static char *ignore = "none";
MODULE_PARM(ignore,"s");
static int bus = -1, slot = -1,function = -1;

static void remove(struct pci_dev *dev)
{
	int i;
	
	printk("reserve: remove device %02x:%02x.%x\n",
	       dev->bus->number,PCI_SLOT(dev->devfn),PCI_FUNC(dev->devfn));
	for (i = 0;; i++) {
		if (0 == pci_resource_start(dev,i))
			break;
		if (pci_resource_start(dev,i) < 0x10000) {
			release_region(pci_resource_start(dev,i),
				       pci_resource_len(dev,i));
		} else {
			release_mem_region(pci_resource_start(dev,i),
					   pci_resource_len(dev,i));
		}
	}
        return;
}

static int __devinit probe(struct pci_dev *dev,
			   const struct pci_device_id *id)
{
	struct resource *res;
	int i;

	if (bus      != dev->bus->number     ||
	    slot     != PCI_SLOT(dev->devfn) ||
	    function != PCI_FUNC(dev->devfn))
		return -EBUSY;

	printk("reserve: probe device %02x:%02x.%x\n",
	       dev->bus->number,PCI_SLOT(dev->devfn),PCI_FUNC(dev->devfn));
	for (i = 0;; i++) {
		if (0 == pci_resource_start(dev,i))
			break;
		if (pci_resource_start(dev,i) < 0x10000) {
			res = request_region(pci_resource_start(dev,i),
					     pci_resource_len(dev,i),
					     "reserve");
			printk("reserve: ... io  at %lx size %lx [%s]\n",
			       pci_resource_start(dev,i),
			       pci_resource_len(dev,i),
			       res ? "ok" : "failed");
			if (!res)
				goto busy;
		} else {
			res = request_mem_region(pci_resource_start(dev,i),
						 pci_resource_len(dev,i),
						 "reserve");
			printk("reserve: ... mem at %lx size %lx [%s]\n",
			       pci_resource_start(dev,i),
			       pci_resource_len(dev,i),
			       res ? "ok" : "failed");
			if (!res)
				goto busy;
		}
	}
	return 0;

 busy:
	i--;
	while (i >= 0) {
		if (pci_resource_start(dev,i) < 0x10000) {
			release_region(pci_resource_start(dev,i),
				       pci_resource_len(dev,i));
		} else {
			release_mem_region(pci_resource_start(dev,i),
					   pci_resource_len(dev,i));
		}
	}
        return -EBUSY;
}

static struct pci_device_id pci_tbl[] __devinitdata = {
        {
		.vendor    = PCI_ANY_ID,
		.device    = PCI_ANY_ID,
		.subvendor = PCI_ANY_ID,
		.subdevice = PCI_ANY_ID,
	},
	{ /* end of list */}
};

MODULE_DEVICE_TABLE(pci, pci_tbl);

static struct pci_driver pci_driver = {
        name:     "reserve",
        id_table: pci_tbl,
        probe:    probe,
        remove:   remove,
};

static int do_init(void)
{
	if (3 == sscanf(ignore,"%x:%x.%x",&bus,&slot,&function)) {
		/* nothing */;
	} else if (2 == sscanf(ignore,"%x.%x",&slot,&function)) {
		bus = 0;
	} else if (2 == sscanf(ignore,"%x:%x",&bus,&slot)) {
		function = 0;
	} else if (1 == sscanf(ignore,"%x",&slot)) {
		bus = 0;
		function = 0;
	} else {
		printk("reserve: can't parse ignore=<device> insmod option\n");
		return -EINVAL;
	}
	printk("reserve: ignore=\"%s\"  ->  using device %02x:%02x.%x\n",
	       ignore,bus,slot,function);
	return pci_module_init(&pci_driver);
}

static void do_fini(void)
{
	pci_unregister_driver(&pci_driver);
}

module_init(do_init);
module_exit(do_fini);

/*
 * Local variables:
 * c-basic-offset: 8
 * End:
 */


  reply	other threads:[~2002-09-11 12:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-10 13:47 ignore pci devices? Gerd Knorr
2002-09-10 14:27 ` Alan Cox
2002-09-11 10:51   ` Gerd Knorr
2002-09-11 11:47     ` Alan Cox
2002-09-11 11:48     ` Alan Cox
2002-09-11 12:33       ` Gerd Knorr
2002-09-10 16:30 ` Martin Mares
2002-09-10 18:42   ` Alan Cox
2002-09-10 18:41     ` Martin Mares
2002-09-10 20:15       ` Alan Cox
2002-09-11 12:20         ` Gerd Knorr [this message]
2002-09-11 12:38           ` Alan Cox
2002-09-11 15:37             ` Gerd Knorr
2002-09-11 16:17               ` Alan Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020911122048.GA6863@bytesex.org \
    --to=kraxel@bytesex.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mj@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox