* Re: ioremap of pci base addresses
[not found] <CA256976.001F00B2.00@d73mta05.au.ibm.com>
@ 2000-10-12 10:52 ` Francois romieu
2000-10-12 15:11 ` Jeff Garzik
0 siblings, 1 reply; 2+ messages in thread
From: Francois romieu @ 2000-10-12 10:52 UTC (permalink / raw)
To: linux-kernel; +Cc: aprasad
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/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: ioremap of pci base addresses
2000-10-12 10:52 ` ioremap of pci base addresses Francois romieu
@ 2000-10-12 15:11 ` Jeff Garzik
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Garzik @ 2000-10-12 15:11 UTC (permalink / raw)
To: Francois romieu; +Cc: linux-kernel, aprasad
Francois romieu wrote:
> token = (unsigned long)ioremap(pci_resource_start(pdev, 0),
> pci_resource_len(pdev, 0));
Looks great except for one small point -- we have been going through
drivers cleaning up where they start casting like this. You should this
token as a void*, and code which uses the value should adjust
accordingly...
Jeff
-
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/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2000-10-12 15:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CA256976.001F00B2.00@d73mta05.au.ibm.com>
2000-10-12 10:52 ` ioremap of pci base addresses Francois romieu
2000-10-12 15:11 ` Jeff Garzik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox