All of lore.kernel.org
 help / color / mirror / Atom feed
From: Manu Abraham <manu@kromtek.com>
To: Jiri Slaby <jirislaby@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: PCI driver
Date: Wed, 14 Sep 2005 16:28:49 +0400	[thread overview]
Message-ID: <43281781.7080308@kromtek.com> (raw)
In-Reply-To: <432815FA.5040202@gmail.com>

Jiri Slaby wrote:

> Manu Abraham napsal(a):
>
>> Jiri Slaby wrote:
>>
>>> Manu Abraham napsal(a):
>>>
>>>> Jiri Slaby wrote:
>>>>
>>>>> Manu Abraham napsal(a):
>>>>>
>>>>>> Now that i have been trying to implement the driver using the new 
>>>>>> PCI API, i feel a bit lost at the different changes gone into the 
>>>>>> PCI API. So if someone could give me a brief idea how a minimal 
>>>>>> PCI probe routine should consist of, that would be quite helpful.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Maybe, you want to read http://lwn.net/Kernel/LDD3/, chapter 12, 
>>>>> pages 311+.
>>>>>
>>>>
>>>> I have been updating myself from LDD2 to LDD3. What i was wondering 
>>>> was in what order should i be calling the functions.
>>>
>>>
>>>
>>>
>>> You won't call anything, kernel does. You only register driver.
>>> struct pcitbl {venids, devids}
>>>
>>> struct driver ... = {probe=a, remove=b, tbl=pcitbl};
>>> a() { if device from pcitbl is in the system (or has been added 
>>> before some little time) this function is called}
>>> b() {if the device was removed from system: modules and hotplug: 
>>> never called; modules: so if modules unload; if both: if the device 
>>> was removed on the fly, or module unload}
>>>
>>> module_init() { register_driver(driver)}
>>> module_exit() { unregister_driver(driver); }
>>>
>>
>> I was wondering whether pci_enable_device() should come first or 
>> pci_dev_put() in the probe routine.
>
> pci_dev_put? No, it counts down reference count, so you would loose 
> the structure. You do NOT do pci_dev_put anymore with pci probing (but 
> some very very specific cases).


Oh, i thought after a pci_dev_get() one does a pci_dev_put()
I wrote something like this, i was now confused with what to do with 
pci_get_drvdata() and pci_set_drvdata()
I am not very sure whether i am doing it right in the first place, since 
my mapped memory seems to be wrong, but first i have to clear up about 
pci_get/set_drvdata().


Manu

static int mantis_pci_probe(*struct* pci_dev *pdev, const *struct* pci_device_id *mantis_pci_table)
{
	*struct* mantis_pci *mantis;
	u8 revision, latency;

	pdev = pci_get_device(PCI_VENDOR_ID_MANTIS, PCI_DEVICE_ID_MANTIS_R11, NULL);
	*if* (pdev) {
		dprintk(verbose, MANTIS_DEBUG, 1, "Found a mantis chip");
		*if* ((mantis = (*struct* mantis_pci *) kmalloc(*sizeof* (*struct* mantis_pci), GFP_KERNEL)) == NULL) {
			dprintk(verbose, MANTIS_ERROR, 1, "Out of memory");
			*return* -ENOMEM;
		}
		*if* (pci_enable_device(pdev) < 0) {
			dprintk(verbose, MANTIS_ERROR, 1, "Could not enable device");
			kfree(mantis);
			*return* -ENODEV;
		}
		mantis->pdev = pdev;
		mantis->mantis_addr = pci_resource_start(pdev, 0);
		*if* (!request_mem_region(pci_resource_start(pdev, 0),
			pci_resource_len(pdev, 0), DRIVER_NAME)) {
			kfree(mantis);
			*return* -EBUSY;
		}
		pci_read_config_byte(mantis->pdev, PCI_CLASS_REVISION, &revision);
		pci_read_config_byte(mantis->pdev, PCI_LATENCY_TIMER, &latency);
		mantis->mantis_mmio = ioremap(mantis->mantis_addr, 0x1000);
		mmwrite(0, MANTIS_INT_STAT); //*		Clear interrupts	*//
		*if* (request_irq(mantis->pdev->irq, (void *) mantis_pci_irq, SA_SHIRQ | 
						SA_INTERRUPT, DRIVER_NAME, (void *) mantis) < 0) {
			dprintk(verbose, MANTIS_ERROR, 1, "Mantis IRQ registration failed");
			release_mem_region(pci_resource_start(mantis->pdev, 0), 
					pci_resource_len(mantis->pdev, 0));
			pci_disable_device(pdev);
			kfree(mantis);
		}
		pci_dev_put(pdev);


	}

	
	*return* 0;
}




  reply	other threads:[~2005-09-14 12:40 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-14  9:34 PCI driver Manu Abraham
2005-09-14 10:03 ` Jiri Slaby
2005-09-14 10:02   ` Manu Abraham
2005-09-14 10:29     ` Jiri Slaby
2005-09-14 11:53       ` Manu Abraham
2005-09-14 12:22         ` Jiri Slaby
2005-09-14 12:28           ` Manu Abraham [this message]
2005-09-14 12:48           ` Manu Abraham
2005-09-14 16:16             ` Jiri Slaby
2005-09-14 17:09               ` Manu Abraham
2005-09-14 19:00                 ` Jiri Slaby
2005-09-14 19:00                   ` Manu Abraham
2005-09-14 19:16                     ` Jiri Slaby
2005-09-14 19:20                       ` Manu Abraham
2005-09-14 22:27                       ` Manu Abraham
2005-09-15  6:43                         ` Rolf Eike Beer
2005-09-15  7:45                           ` Manu Abraham
2005-09-15  8:18                             ` Rolf Eike Beer
2005-09-15  8:51                               ` Manu Abraham
2005-09-15  9:48                                 ` Rolf Eike Beer
2005-09-15 14:38                                   ` Manu Abraham
2005-09-15 14:57                                     ` Rolf Eike Beer
2005-09-15 16:59                                       ` Manu Abraham
2005-09-15 18:29                                       ` Manu Abraham
2005-09-15 10:29                                 ` Ralph Metzler
2005-09-15 10:35                                   ` Manu Abraham
2005-09-15 11:42                                   ` Manu Abraham
2005-09-15 12:08                                     ` Antonino A. Daplas
2005-09-15 12:24                                       ` Rolf Eike Beer
2005-09-15 12:32                                       ` Manu Abraham
2005-09-15 12:08                                     ` Rolf Eike Beer
2005-10-10 12:02                         ` Rolf Eike Beer
2005-10-10 12:48                           ` Manu Abraham
2005-10-10 13:25                             ` Rolf Eike Beer
2005-10-10 13:16                               ` Manu Abraham
     [not found]                             ` <3888a5cd0510100719r3fddc368oa01e07e2c42b71e@mail.gmail.com>
2005-10-10 15:00                               ` Manu Abraham
     [not found]                                 ` <3888a5cd0510100846p7f2ff70cid69a1136b9256ab6@mail.gmail.com>
2005-10-10 17:08                                   ` Manu Abraham
     [not found]                                     ` <4af2d03a0510101101n54ab0b1cvae177c3c992bf9a9@mail.gmail.com>
2005-10-10 18:28                                       ` Manu Abraham
     [not found]                             ` <3888a5cd0510100725k579809a9o374930df9988bfa3@mail.gmail.com>
2005-10-10 15:02                               ` Manu Abraham
     [not found]                           ` <4af2d03a0510100528y236a1246tfc56c08a78f072d5@mail.gmail.com>
2005-10-10 12:51                             ` Manu Abraham
  -- strict thread matches above, loose matches on Subject: below --
2006-08-27 16:24 Lee Revell
2006-08-28  4:10 ` Lee Revell
2010-08-28 12:17 pci driver Srinivas Mankan

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=43281781.7080308@kromtek.com \
    --to=manu@kromtek.com \
    --cc=jirislaby@gmail.com \
    --cc=linux-kernel@vger.kernel.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.