All of lore.kernel.org
 help / color / mirror / Atom feed
From: greg@kroah.com (Greg KH)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Faking PCI devices?
Date: Wed, 4 May 2011 07:55:13 -0700	[thread overview]
Message-ID: <20110504145513.GA12265@kroah.com> (raw)
In-Reply-To: <BANLkTikFCqqNO9G-6w2Yck0CEbNQ0eF-YQ@mail.gmail.com>

On Wed, May 04, 2011 at 11:39:20AM +0200, Manohar Vanga wrote:
> Hi,
> 
> I have written a simulated driver for a PCI board and am looking for a clean
> way to use the driver. Currently, I am setting the PCI ids to PCI_ANY_ID and
> only allowing a single probe call to go through using a global variable
> (concurrency issues but I don't care for the simulation).
> 
> static int n
> ...
> static int fake_board_probe(struct pci_dev *pdev, const struct pci_device_id
> *ent)
> {
> ??? if (n == 1)
> ??????? return -1;

Please return a proper error value, like -ENODEV.

> ??? n = 1;
> ??? ...
> }
> static int fake_board_init(void)
> {
> ??? n = 0;
> ??? ....
> }
> 
> I want to do a cleaner job of this and wanted to write a PCI bridge driver that
> actually registers the devices with the correct IDs that I need. This also
> gives me the advantage of being able to register multiple devices which is a
> useful for the simulation I am working on.
> Can anyone point me in the right direction for this? Most of the code (eg.
> struct pci_controller) seem to be architecture specific.

Just register your device, and then don't use any global variables to
the driver.  Put them all in your struct pci_dev private area and you
will be fine.

There's thousands of examples of this in the kernel.

hope this helps,

greg k-h

      reply	other threads:[~2011-05-04 14:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-04  9:39 Faking PCI devices? Manohar Vanga
2011-05-04 14:55 ` Greg KH [this message]

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=20110504145513.GA12265@kroah.com \
    --to=greg@kroah.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.