public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Francois romieu <romieu@ensta.fr>
To: linux-kernel@vger.kernel.org
Cc: aprasad@in.ibm.com
Subject: Re: ioremap of pci base addresses
Date: Thu, 12 Oct 2000 10:52:00 +0000	[thread overview]
Message-ID: <20001012105200.A28642@nic.fr> (raw)
In-Reply-To: <CA256976.001F00B2.00@d73mta05.au.ibm.com>

The Thu, Oct 12, 2000 at 11:02:50AM +0530, aprasad@in.ibm.com wrote :
> once i have got the pci_dev structure( by calling pci_find*), do i
> explicitly need to call ioremap for remapping mmio.
> i think pci_enable_device does this. correct me if i am wrong..

ioremap does not only remap mmio but returns a token that should be
used if you want to further access the mmapped area (readl(token) and
writel(some_data, token) for example).

Part of 'foo' code could look like this :

static struct pci_driver foo_driver = {
        name:           "foo",
        id_table:       foo_pci_tbl,
        probe:          foo_init_one,
        remove:         foo_remove_one,
};

static int __init foo_init_one (struct pci_dev *pdev, 
				struct pci_device_id *ent)
{
	u32 token;

	if (pci_enable_device(pdev))
		goto err_out;

	/* 
	 * Some area (non pci-configuration registers or other) one wants to 
	 * mmap. Ask 'foo' manual for the description of the Base Address 
	 * Register in foo's pci configuration space.
	 */
	if (!request_mem_region(pci_resource_start(pdev, 0), 
				pci_resource_len(pdev, 0), "mmaped registers")) {
		printk(KERN_ERR "foo: can't reserve MMIO region\n");
		goto err_out;
	}
	token =  = (unsigned long)ioremap(pci_resource_start(pdev, 0),
					  pci_resource_len(pdev, 0));

	/* 
	 * The following will happen if one forgets to balance ioremap
	 * and iounmap at insmod/rmmod time for example.
	 */
	if (!token) {
		printk(KERN_ERR "foo: cannot remap MMIO region %lx @ %lx\n",
		       pci_resource_len(pdev, 0), pci_resource_start(pdev, 0));
		goto err_out_free_mmio_region;
	}

	[more stuff that may fail and should go at least to label err_out_iounmap]

	return 0;

err_out_iounmap: 
	iounmap ((void *)token);
err_out_free_mmio_region:
	release_mem_region(pci_resource_start(pdev, 0), 
			   pci_resource_len(pdev, 0));
err_out:
	return -ENODEV;
}

static void foo_remove_one (struct pci_dev *pdev)
{
	[some stuff]

	iounmap((void *)some_safe_structure->token);

	[kfree may appear...]

	release_mem_region(pci_resource_start(pdev, 0),
			   pci_resource_len(pdev, 0));
}

-- 
Ueimor
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

       reply	other threads:[~2000-10-12  9:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CA256976.001F00B2.00@d73mta05.au.ibm.com>
2000-10-12 10:52 ` Francois romieu [this message]
2000-10-12 15:11   ` ioremap of pci base addresses Jeff Garzik

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=20001012105200.A28642@nic.fr \
    --to=romieu@ensta.fr \
    --cc=aprasad@in.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox