2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Linux Plug and Play Support
|
|
|
|
* Copyright by Adam Belay <ambx1@neo.rr.com>
|
PNP: convert resource options to single linked list
ISAPNP, PNPBIOS, and ACPI describe the "possible resource settings" of
a device, i.e., the possibilities an OS bus driver has when it assigns
I/O port, MMIO, and other resources to the device.
PNP used to maintain this "possible resource setting" information in
one independent option structure and a list of dependent option
structures for each device. Each of these option structures had lists
of I/O, memory, IRQ, and DMA resources, for example:
dev
independent options
ind-io0 -> ind-io1 ...
ind-mem0 -> ind-mem1 ...
...
dependent option set 0
dep0-io0 -> dep0-io1 ...
dep0-mem0 -> dep0-mem1 ...
...
dependent option set 1
dep1-io0 -> dep1-io1 ...
dep1-mem0 -> dep1-mem1 ...
...
...
This data structure was designed for ISAPNP, where the OS configures
device resource settings by writing directly to configuration
registers. The OS can write the registers in arbitrary order much
like it writes PCI BARs.
However, for PNPBIOS and ACPI devices, the OS uses firmware interfaces
that perform device configuration, and it is important to pass the
desired settings to those interfaces in the correct order. The OS
learns the correct order by using firmware interfaces that return the
"current resource settings" and "possible resource settings," but the
option structures above doesn't store the ordering information.
This patch replaces the independent and dependent lists with a single
list of options. For example, a device might have possible resource
settings like this:
dev
options
ind-io0 -> dep0-io0 -> dep1->io0 -> ind-io1 ...
All the possible settings are in the same list, in the order they
come from the firmware "possible resource settings" list. Each entry
is tagged with an independent/dependent flag. Dependent entries also
have a "set number" and an optional priority value. All dependent
entries must be assigned from the same set. For example, the OS can
use all the entries from dependent set 0, or all the entries from
dependent set 1, but it cannot mix entries from set 0 with entries
from set 1.
Prior to this patch PNP didn't keep track of the order of this list,
and it assigned all independent options first, then all dependent
ones. Using the example above, that resulted in a "desired
configuration" list like this:
ind->io0 -> ind->io1 -> depN-io0 ...
instead of the list the firmware expects, which looks like this:
ind->io0 -> depN-io0 -> ind-io1 ...
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Rene Herman <rene.herman@gmail.com>
Signed-off-by: Len Brown <len.brown@intel.com>
2008-06-28 05:57:17 +07:00
|
|
|
* Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
|
|
|
|
* Bjorn Helgaas <bjorn.helgaas@hp.com>
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_PNP_H
|
|
|
|
#define _LINUX_PNP_H
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/mod_devicetable.h>
|
2015-01-22 23:50:24 +07:00
|
|
|
#include <linux/console.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#define PNP_NAME_LEN 50
|
|
|
|
|
|
|
|
struct pnp_protocol;
|
|
|
|
struct pnp_dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resource Management
|
|
|
|
*/
|
2008-09-17 05:00:11 +07:00
|
|
|
#ifdef CONFIG_PNP
|
2008-10-16 12:03:58 +07:00
|
|
|
struct resource *pnp_get_resource(struct pnp_dev *dev, unsigned long type,
|
|
|
|
unsigned int num);
|
2008-09-17 05:00:11 +07:00
|
|
|
#else
|
2008-10-16 12:03:58 +07:00
|
|
|
static inline struct resource *pnp_get_resource(struct pnp_dev *dev,
|
|
|
|
unsigned long type, unsigned int num)
|
2008-09-17 05:00:11 +07:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-04-29 05:34:16 +07:00
|
|
|
static inline int pnp_resource_valid(struct resource *res)
|
|
|
|
{
|
PNP: replace pnp_resource_table with dynamically allocated resources
PNP used to have a fixed-size pnp_resource_table for tracking the
resources used by a device. This table often overflowed, so we've
had to increase the table size, which wastes memory because most
devices have very few resources.
This patch replaces the table with a linked list of resources where
the entries are allocated on demand.
This removes messages like these:
pnpacpi: exceeded the max number of IO resources
00:01: too many I/O port resources
References:
http://bugzilla.kernel.org/show_bug.cgi?id=9535
http://bugzilla.kernel.org/show_bug.cgi?id=9740
http://lkml.org/lkml/2007/11/30/110
This patch also changes the way PNP uses the IORESOURCE_UNSET,
IORESOURCE_AUTO, and IORESOURCE_DISABLED flags.
Prior to this patch, the pnp_resource_table entries used the flags
like this:
IORESOURCE_UNSET
This table entry is unused and available for use. When this flag
is set, we shouldn't look at anything else in the resource structure.
This flag is set when a resource table entry is initialized.
IORESOURCE_AUTO
This resource was assigned automatically by pnp_assign_{io,mem,etc}().
This flag is set when a resource table entry is initialized and
cleared whenever we discover a resource setting by reading an ISAPNP
config register, parsing a PNPBIOS resource data stream, parsing an
ACPI _CRS list, or interpreting a sysfs "set" command.
Resources marked IORESOURCE_AUTO are reinitialized and marked as
IORESOURCE_UNSET by pnp_clean_resource_table() in these cases:
- before we attempt to assign resources automatically,
- if we fail to assign resources automatically,
- after disabling a device
IORESOURCE_DISABLED
Set by pnp_assign_{io,mem,etc}() when automatic assignment fails.
Also set by PNPBIOS and PNPACPI for:
- invalid IRQs or GSI registration failures
- invalid DMA channels
- I/O ports above 0x10000
- mem ranges with negative length
After this patch, there is no pnp_resource_table, and the resource list
entries use the flags like this:
IORESOURCE_UNSET
This flag is no longer used in PNP. Instead of keeping
IORESOURCE_UNSET entries in the resource list, we remove
entries from the list and free them.
IORESOURCE_AUTO
No change in meaning: it still means the resource was assigned
automatically by pnp_assign_{port,mem,etc}(), but these functions
now set the bit explicitly.
We still "clean" a device's resource list in the same places,
but rather than reinitializing IORESOURCE_AUTO entries, we
just remove them from the list.
Note that IORESOURCE_AUTO entries are always at the end of the
list, so removing them doesn't reorder other list entries.
This is because non-IORESOURCE_AUTO entries are added by the
ISAPNP, PNPBIOS, or PNPACPI "get resources" methods and by the
sysfs "set" command. In each of these cases, we completely free
the resource list first.
IORESOURCE_DISABLED
In addition to the cases where we used to set this flag, ISAPNP now
adds an IORESOURCE_DISABLED resource when it reads a configuration
register with a "disabled" value.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
2008-06-28 05:56:57 +07:00
|
|
|
if (res)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pnp_resource_enabled(struct resource *res)
|
|
|
|
{
|
|
|
|
if (res && !(res->flags & IORESOURCE_DISABLED))
|
2008-04-29 05:34:16 +07:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline resource_size_t pnp_resource_len(struct resource *res)
|
|
|
|
{
|
|
|
|
if (res->start == 0 && res->end == 0)
|
|
|
|
return 0;
|
2011-06-09 23:13:32 +07:00
|
|
|
return resource_size(res);
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline resource_size_t pnp_port_start(struct pnp_dev *dev,
|
|
|
|
unsigned int bar)
|
|
|
|
{
|
2008-06-28 05:56:56 +07:00
|
|
|
struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
|
|
|
|
|
|
|
|
if (pnp_resource_valid(res))
|
|
|
|
return res->start;
|
|
|
|
return 0;
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline resource_size_t pnp_port_end(struct pnp_dev *dev,
|
|
|
|
unsigned int bar)
|
|
|
|
{
|
2008-06-28 05:56:56 +07:00
|
|
|
struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
|
|
|
|
|
|
|
|
if (pnp_resource_valid(res))
|
|
|
|
return res->end;
|
|
|
|
return 0;
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long pnp_port_flags(struct pnp_dev *dev,
|
|
|
|
unsigned int bar)
|
|
|
|
{
|
2008-06-28 05:56:56 +07:00
|
|
|
struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
|
|
|
|
|
|
|
|
if (pnp_resource_valid(res))
|
|
|
|
return res->flags;
|
PNP: replace pnp_resource_table with dynamically allocated resources
PNP used to have a fixed-size pnp_resource_table for tracking the
resources used by a device. This table often overflowed, so we've
had to increase the table size, which wastes memory because most
devices have very few resources.
This patch replaces the table with a linked list of resources where
the entries are allocated on demand.
This removes messages like these:
pnpacpi: exceeded the max number of IO resources
00:01: too many I/O port resources
References:
http://bugzilla.kernel.org/show_bug.cgi?id=9535
http://bugzilla.kernel.org/show_bug.cgi?id=9740
http://lkml.org/lkml/2007/11/30/110
This patch also changes the way PNP uses the IORESOURCE_UNSET,
IORESOURCE_AUTO, and IORESOURCE_DISABLED flags.
Prior to this patch, the pnp_resource_table entries used the flags
like this:
IORESOURCE_UNSET
This table entry is unused and available for use. When this flag
is set, we shouldn't look at anything else in the resource structure.
This flag is set when a resource table entry is initialized.
IORESOURCE_AUTO
This resource was assigned automatically by pnp_assign_{io,mem,etc}().
This flag is set when a resource table entry is initialized and
cleared whenever we discover a resource setting by reading an ISAPNP
config register, parsing a PNPBIOS resource data stream, parsing an
ACPI _CRS list, or interpreting a sysfs "set" command.
Resources marked IORESOURCE_AUTO are reinitialized and marked as
IORESOURCE_UNSET by pnp_clean_resource_table() in these cases:
- before we attempt to assign resources automatically,
- if we fail to assign resources automatically,
- after disabling a device
IORESOURCE_DISABLED
Set by pnp_assign_{io,mem,etc}() when automatic assignment fails.
Also set by PNPBIOS and PNPACPI for:
- invalid IRQs or GSI registration failures
- invalid DMA channels
- I/O ports above 0x10000
- mem ranges with negative length
After this patch, there is no pnp_resource_table, and the resource list
entries use the flags like this:
IORESOURCE_UNSET
This flag is no longer used in PNP. Instead of keeping
IORESOURCE_UNSET entries in the resource list, we remove
entries from the list and free them.
IORESOURCE_AUTO
No change in meaning: it still means the resource was assigned
automatically by pnp_assign_{port,mem,etc}(), but these functions
now set the bit explicitly.
We still "clean" a device's resource list in the same places,
but rather than reinitializing IORESOURCE_AUTO entries, we
just remove them from the list.
Note that IORESOURCE_AUTO entries are always at the end of the
list, so removing them doesn't reorder other list entries.
This is because non-IORESOURCE_AUTO entries are added by the
ISAPNP, PNPBIOS, or PNPACPI "get resources" methods and by the
sysfs "set" command. In each of these cases, we completely free
the resource list first.
IORESOURCE_DISABLED
In addition to the cases where we used to set this flag, ISAPNP now
adds an IORESOURCE_DISABLED resource when it reads a configuration
register with a "disabled" value.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
2008-06-28 05:56:57 +07:00
|
|
|
return IORESOURCE_IO | IORESOURCE_AUTO;
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar)
|
|
|
|
{
|
|
|
|
return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IO, bar));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline resource_size_t pnp_port_len(struct pnp_dev *dev,
|
|
|
|
unsigned int bar)
|
|
|
|
{
|
2008-06-28 05:56:56 +07:00
|
|
|
struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
|
|
|
|
|
|
|
|
if (pnp_resource_valid(res))
|
|
|
|
return pnp_resource_len(res);
|
|
|
|
return 0;
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline resource_size_t pnp_mem_start(struct pnp_dev *dev,
|
|
|
|
unsigned int bar)
|
|
|
|
{
|
2008-06-28 05:56:56 +07:00
|
|
|
struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
|
|
|
|
|
|
|
|
if (pnp_resource_valid(res))
|
|
|
|
return res->start;
|
|
|
|
return 0;
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline resource_size_t pnp_mem_end(struct pnp_dev *dev,
|
|
|
|
unsigned int bar)
|
|
|
|
{
|
2008-06-28 05:56:56 +07:00
|
|
|
struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
|
|
|
|
|
|
|
|
if (pnp_resource_valid(res))
|
|
|
|
return res->end;
|
|
|
|
return 0;
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar)
|
|
|
|
{
|
2008-06-28 05:56:56 +07:00
|
|
|
struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
|
|
|
|
|
|
|
|
if (pnp_resource_valid(res))
|
|
|
|
return res->flags;
|
PNP: replace pnp_resource_table with dynamically allocated resources
PNP used to have a fixed-size pnp_resource_table for tracking the
resources used by a device. This table often overflowed, so we've
had to increase the table size, which wastes memory because most
devices have very few resources.
This patch replaces the table with a linked list of resources where
the entries are allocated on demand.
This removes messages like these:
pnpacpi: exceeded the max number of IO resources
00:01: too many I/O port resources
References:
http://bugzilla.kernel.org/show_bug.cgi?id=9535
http://bugzilla.kernel.org/show_bug.cgi?id=9740
http://lkml.org/lkml/2007/11/30/110
This patch also changes the way PNP uses the IORESOURCE_UNSET,
IORESOURCE_AUTO, and IORESOURCE_DISABLED flags.
Prior to this patch, the pnp_resource_table entries used the flags
like this:
IORESOURCE_UNSET
This table entry is unused and available for use. When this flag
is set, we shouldn't look at anything else in the resource structure.
This flag is set when a resource table entry is initialized.
IORESOURCE_AUTO
This resource was assigned automatically by pnp_assign_{io,mem,etc}().
This flag is set when a resource table entry is initialized and
cleared whenever we discover a resource setting by reading an ISAPNP
config register, parsing a PNPBIOS resource data stream, parsing an
ACPI _CRS list, or interpreting a sysfs "set" command.
Resources marked IORESOURCE_AUTO are reinitialized and marked as
IORESOURCE_UNSET by pnp_clean_resource_table() in these cases:
- before we attempt to assign resources automatically,
- if we fail to assign resources automatically,
- after disabling a device
IORESOURCE_DISABLED
Set by pnp_assign_{io,mem,etc}() when automatic assignment fails.
Also set by PNPBIOS and PNPACPI for:
- invalid IRQs or GSI registration failures
- invalid DMA channels
- I/O ports above 0x10000
- mem ranges with negative length
After this patch, there is no pnp_resource_table, and the resource list
entries use the flags like this:
IORESOURCE_UNSET
This flag is no longer used in PNP. Instead of keeping
IORESOURCE_UNSET entries in the resource list, we remove
entries from the list and free them.
IORESOURCE_AUTO
No change in meaning: it still means the resource was assigned
automatically by pnp_assign_{port,mem,etc}(), but these functions
now set the bit explicitly.
We still "clean" a device's resource list in the same places,
but rather than reinitializing IORESOURCE_AUTO entries, we
just remove them from the list.
Note that IORESOURCE_AUTO entries are always at the end of the
list, so removing them doesn't reorder other list entries.
This is because non-IORESOURCE_AUTO entries are added by the
ISAPNP, PNPBIOS, or PNPACPI "get resources" methods and by the
sysfs "set" command. In each of these cases, we completely free
the resource list first.
IORESOURCE_DISABLED
In addition to the cases where we used to set this flag, ISAPNP now
adds an IORESOURCE_DISABLED resource when it reads a configuration
register with a "disabled" value.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
2008-06-28 05:56:57 +07:00
|
|
|
return IORESOURCE_MEM | IORESOURCE_AUTO;
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar)
|
|
|
|
{
|
|
|
|
return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_MEM, bar));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline resource_size_t pnp_mem_len(struct pnp_dev *dev,
|
|
|
|
unsigned int bar)
|
|
|
|
{
|
2008-06-28 05:56:56 +07:00
|
|
|
struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
|
|
|
|
|
|
|
|
if (pnp_resource_valid(res))
|
|
|
|
return pnp_resource_len(res);
|
|
|
|
return 0;
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar)
|
|
|
|
{
|
2008-06-28 05:56:56 +07:00
|
|
|
struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar);
|
|
|
|
|
|
|
|
if (pnp_resource_valid(res))
|
|
|
|
return res->start;
|
|
|
|
return -1;
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar)
|
|
|
|
{
|
2008-06-28 05:56:56 +07:00
|
|
|
struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar);
|
|
|
|
|
|
|
|
if (pnp_resource_valid(res))
|
|
|
|
return res->flags;
|
PNP: replace pnp_resource_table with dynamically allocated resources
PNP used to have a fixed-size pnp_resource_table for tracking the
resources used by a device. This table often overflowed, so we've
had to increase the table size, which wastes memory because most
devices have very few resources.
This patch replaces the table with a linked list of resources where
the entries are allocated on demand.
This removes messages like these:
pnpacpi: exceeded the max number of IO resources
00:01: too many I/O port resources
References:
http://bugzilla.kernel.org/show_bug.cgi?id=9535
http://bugzilla.kernel.org/show_bug.cgi?id=9740
http://lkml.org/lkml/2007/11/30/110
This patch also changes the way PNP uses the IORESOURCE_UNSET,
IORESOURCE_AUTO, and IORESOURCE_DISABLED flags.
Prior to this patch, the pnp_resource_table entries used the flags
like this:
IORESOURCE_UNSET
This table entry is unused and available for use. When this flag
is set, we shouldn't look at anything else in the resource structure.
This flag is set when a resource table entry is initialized.
IORESOURCE_AUTO
This resource was assigned automatically by pnp_assign_{io,mem,etc}().
This flag is set when a resource table entry is initialized and
cleared whenever we discover a resource setting by reading an ISAPNP
config register, parsing a PNPBIOS resource data stream, parsing an
ACPI _CRS list, or interpreting a sysfs "set" command.
Resources marked IORESOURCE_AUTO are reinitialized and marked as
IORESOURCE_UNSET by pnp_clean_resource_table() in these cases:
- before we attempt to assign resources automatically,
- if we fail to assign resources automatically,
- after disabling a device
IORESOURCE_DISABLED
Set by pnp_assign_{io,mem,etc}() when automatic assignment fails.
Also set by PNPBIOS and PNPACPI for:
- invalid IRQs or GSI registration failures
- invalid DMA channels
- I/O ports above 0x10000
- mem ranges with negative length
After this patch, there is no pnp_resource_table, and the resource list
entries use the flags like this:
IORESOURCE_UNSET
This flag is no longer used in PNP. Instead of keeping
IORESOURCE_UNSET entries in the resource list, we remove
entries from the list and free them.
IORESOURCE_AUTO
No change in meaning: it still means the resource was assigned
automatically by pnp_assign_{port,mem,etc}(), but these functions
now set the bit explicitly.
We still "clean" a device's resource list in the same places,
but rather than reinitializing IORESOURCE_AUTO entries, we
just remove them from the list.
Note that IORESOURCE_AUTO entries are always at the end of the
list, so removing them doesn't reorder other list entries.
This is because non-IORESOURCE_AUTO entries are added by the
ISAPNP, PNPBIOS, or PNPACPI "get resources" methods and by the
sysfs "set" command. In each of these cases, we completely free
the resource list first.
IORESOURCE_DISABLED
In addition to the cases where we used to set this flag, ISAPNP now
adds an IORESOURCE_DISABLED resource when it reads a configuration
register with a "disabled" value.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
2008-06-28 05:56:57 +07:00
|
|
|
return IORESOURCE_IRQ | IORESOURCE_AUTO;
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar)
|
|
|
|
{
|
|
|
|
return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IRQ, bar));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline resource_size_t pnp_dma(struct pnp_dev *dev, unsigned int bar)
|
|
|
|
{
|
2008-06-28 05:56:56 +07:00
|
|
|
struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar);
|
|
|
|
|
|
|
|
if (pnp_resource_valid(res))
|
|
|
|
return res->start;
|
|
|
|
return -1;
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar)
|
|
|
|
{
|
2008-06-28 05:56:56 +07:00
|
|
|
struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar);
|
|
|
|
|
|
|
|
if (pnp_resource_valid(res))
|
|
|
|
return res->flags;
|
PNP: replace pnp_resource_table with dynamically allocated resources
PNP used to have a fixed-size pnp_resource_table for tracking the
resources used by a device. This table often overflowed, so we've
had to increase the table size, which wastes memory because most
devices have very few resources.
This patch replaces the table with a linked list of resources where
the entries are allocated on demand.
This removes messages like these:
pnpacpi: exceeded the max number of IO resources
00:01: too many I/O port resources
References:
http://bugzilla.kernel.org/show_bug.cgi?id=9535
http://bugzilla.kernel.org/show_bug.cgi?id=9740
http://lkml.org/lkml/2007/11/30/110
This patch also changes the way PNP uses the IORESOURCE_UNSET,
IORESOURCE_AUTO, and IORESOURCE_DISABLED flags.
Prior to this patch, the pnp_resource_table entries used the flags
like this:
IORESOURCE_UNSET
This table entry is unused and available for use. When this flag
is set, we shouldn't look at anything else in the resource structure.
This flag is set when a resource table entry is initialized.
IORESOURCE_AUTO
This resource was assigned automatically by pnp_assign_{io,mem,etc}().
This flag is set when a resource table entry is initialized and
cleared whenever we discover a resource setting by reading an ISAPNP
config register, parsing a PNPBIOS resource data stream, parsing an
ACPI _CRS list, or interpreting a sysfs "set" command.
Resources marked IORESOURCE_AUTO are reinitialized and marked as
IORESOURCE_UNSET by pnp_clean_resource_table() in these cases:
- before we attempt to assign resources automatically,
- if we fail to assign resources automatically,
- after disabling a device
IORESOURCE_DISABLED
Set by pnp_assign_{io,mem,etc}() when automatic assignment fails.
Also set by PNPBIOS and PNPACPI for:
- invalid IRQs or GSI registration failures
- invalid DMA channels
- I/O ports above 0x10000
- mem ranges with negative length
After this patch, there is no pnp_resource_table, and the resource list
entries use the flags like this:
IORESOURCE_UNSET
This flag is no longer used in PNP. Instead of keeping
IORESOURCE_UNSET entries in the resource list, we remove
entries from the list and free them.
IORESOURCE_AUTO
No change in meaning: it still means the resource was assigned
automatically by pnp_assign_{port,mem,etc}(), but these functions
now set the bit explicitly.
We still "clean" a device's resource list in the same places,
but rather than reinitializing IORESOURCE_AUTO entries, we
just remove them from the list.
Note that IORESOURCE_AUTO entries are always at the end of the
list, so removing them doesn't reorder other list entries.
This is because non-IORESOURCE_AUTO entries are added by the
ISAPNP, PNPBIOS, or PNPACPI "get resources" methods and by the
sysfs "set" command. In each of these cases, we completely free
the resource list first.
IORESOURCE_DISABLED
In addition to the cases where we used to set this flag, ISAPNP now
adds an IORESOURCE_DISABLED resource when it reads a configuration
register with a "disabled" value.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
2008-06-28 05:56:57 +07:00
|
|
|
return IORESOURCE_DMA | IORESOURCE_AUTO;
|
2008-04-29 05:34:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar)
|
|
|
|
{
|
|
|
|
return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_DMA, bar));
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2008-02-03 22:45:46 +07:00
|
|
|
* Device Management
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct pnp_card {
|
2007-07-27 00:41:21 +07:00
|
|
|
struct device dev; /* Driver Model device interface */
|
|
|
|
unsigned char number; /* used as an index, must be unique */
|
2005-04-17 05:20:36 +07:00
|
|
|
struct list_head global_list; /* node in global list of cards */
|
|
|
|
struct list_head protocol_list; /* node in protocol's list of cards */
|
|
|
|
struct list_head devices; /* devices attached to the card */
|
|
|
|
|
2007-07-27 00:41:20 +07:00
|
|
|
struct pnp_protocol *protocol;
|
2007-07-27 00:41:21 +07:00
|
|
|
struct pnp_id *id; /* contains supported EISA IDs */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
char name[PNP_NAME_LEN]; /* contains a human-readable name */
|
2007-07-27 00:41:21 +07:00
|
|
|
unsigned char pnpver; /* Plug & Play version */
|
2007-07-27 00:41:20 +07:00
|
|
|
unsigned char productver; /* product version */
|
2007-07-27 00:41:21 +07:00
|
|
|
unsigned int serial; /* serial number */
|
|
|
|
unsigned char checksum; /* if zero - checksum passed */
|
2005-04-17 05:20:36 +07:00
|
|
|
struct proc_dir_entry *procdir; /* directory entry in /proc/bus/isapnp */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define global_to_pnp_card(n) list_entry(n, struct pnp_card, global_list)
|
|
|
|
#define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list)
|
|
|
|
#define to_pnp_card(n) container_of(n, struct pnp_card, dev)
|
|
|
|
#define pnp_for_each_card(card) \
|
|
|
|
for((card) = global_to_pnp_card(pnp_cards.next); \
|
|
|
|
(card) != global_to_pnp_card(&pnp_cards); \
|
|
|
|
(card) = global_to_pnp_card((card)->global_list.next))
|
|
|
|
|
|
|
|
struct pnp_card_link {
|
2007-07-27 00:41:20 +07:00
|
|
|
struct pnp_card *card;
|
|
|
|
struct pnp_card_driver *driver;
|
|
|
|
void *driver_data;
|
2005-11-29 15:09:32 +07:00
|
|
|
pm_message_t pm_state;
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2007-07-27 00:41:20 +07:00
|
|
|
static inline void *pnp_get_card_drvdata(struct pnp_card_link *pcard)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
return pcard->driver_data;
|
|
|
|
}
|
|
|
|
|
2007-07-27 00:41:20 +07:00
|
|
|
static inline void pnp_set_card_drvdata(struct pnp_card_link *pcard, void *data)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
pcard->driver_data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pnp_dev {
|
2007-07-27 00:41:21 +07:00
|
|
|
struct device dev; /* Driver Model device interface */
|
2007-05-08 14:25:29 +07:00
|
|
|
u64 dma_mask;
|
2008-04-11 11:29:28 +07:00
|
|
|
unsigned int number; /* used as an index, must be unique */
|
2005-04-17 05:20:36 +07:00
|
|
|
int status;
|
|
|
|
|
|
|
|
struct list_head global_list; /* node in global list of devices */
|
|
|
|
struct list_head protocol_list; /* node in list of device's protocol */
|
|
|
|
struct list_head card_list; /* node in card's list of devices */
|
|
|
|
struct list_head rdev_list; /* node in cards list of requested devices */
|
|
|
|
|
2007-07-27 00:41:20 +07:00
|
|
|
struct pnp_protocol *protocol;
|
|
|
|
struct pnp_card *card; /* card the device is attached to, none if NULL */
|
|
|
|
struct pnp_driver *driver;
|
|
|
|
struct pnp_card_link *card_link;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-07-27 00:41:21 +07:00
|
|
|
struct pnp_id *id; /* supported EISA IDs */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
int active;
|
|
|
|
int capabilities;
|
PNP: convert resource options to single linked list
ISAPNP, PNPBIOS, and ACPI describe the "possible resource settings" of
a device, i.e., the possibilities an OS bus driver has when it assigns
I/O port, MMIO, and other resources to the device.
PNP used to maintain this "possible resource setting" information in
one independent option structure and a list of dependent option
structures for each device. Each of these option structures had lists
of I/O, memory, IRQ, and DMA resources, for example:
dev
independent options
ind-io0 -> ind-io1 ...
ind-mem0 -> ind-mem1 ...
...
dependent option set 0
dep0-io0 -> dep0-io1 ...
dep0-mem0 -> dep0-mem1 ...
...
dependent option set 1
dep1-io0 -> dep1-io1 ...
dep1-mem0 -> dep1-mem1 ...
...
...
This data structure was designed for ISAPNP, where the OS configures
device resource settings by writing directly to configuration
registers. The OS can write the registers in arbitrary order much
like it writes PCI BARs.
However, for PNPBIOS and ACPI devices, the OS uses firmware interfaces
that perform device configuration, and it is important to pass the
desired settings to those interfaces in the correct order. The OS
learns the correct order by using firmware interfaces that return the
"current resource settings" and "possible resource settings," but the
option structures above doesn't store the ordering information.
This patch replaces the independent and dependent lists with a single
list of options. For example, a device might have possible resource
settings like this:
dev
options
ind-io0 -> dep0-io0 -> dep1->io0 -> ind-io1 ...
All the possible settings are in the same list, in the order they
come from the firmware "possible resource settings" list. Each entry
is tagged with an independent/dependent flag. Dependent entries also
have a "set number" and an optional priority value. All dependent
entries must be assigned from the same set. For example, the OS can
use all the entries from dependent set 0, or all the entries from
dependent set 1, but it cannot mix entries from set 0 with entries
from set 1.
Prior to this patch PNP didn't keep track of the order of this list,
and it assigned all independent options first, then all dependent
ones. Using the example above, that resulted in a "desired
configuration" list like this:
ind->io0 -> ind->io1 -> depN-io0 ...
instead of the list the firmware expects, which looks like this:
ind->io0 -> depN-io0 -> ind-io1 ...
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Rene Herman <rene.herman@gmail.com>
Signed-off-by: Len Brown <len.brown@intel.com>
2008-06-28 05:57:17 +07:00
|
|
|
unsigned int num_dependent_sets;
|
PNP: replace pnp_resource_table with dynamically allocated resources
PNP used to have a fixed-size pnp_resource_table for tracking the
resources used by a device. This table often overflowed, so we've
had to increase the table size, which wastes memory because most
devices have very few resources.
This patch replaces the table with a linked list of resources where
the entries are allocated on demand.
This removes messages like these:
pnpacpi: exceeded the max number of IO resources
00:01: too many I/O port resources
References:
http://bugzilla.kernel.org/show_bug.cgi?id=9535
http://bugzilla.kernel.org/show_bug.cgi?id=9740
http://lkml.org/lkml/2007/11/30/110
This patch also changes the way PNP uses the IORESOURCE_UNSET,
IORESOURCE_AUTO, and IORESOURCE_DISABLED flags.
Prior to this patch, the pnp_resource_table entries used the flags
like this:
IORESOURCE_UNSET
This table entry is unused and available for use. When this flag
is set, we shouldn't look at anything else in the resource structure.
This flag is set when a resource table entry is initialized.
IORESOURCE_AUTO
This resource was assigned automatically by pnp_assign_{io,mem,etc}().
This flag is set when a resource table entry is initialized and
cleared whenever we discover a resource setting by reading an ISAPNP
config register, parsing a PNPBIOS resource data stream, parsing an
ACPI _CRS list, or interpreting a sysfs "set" command.
Resources marked IORESOURCE_AUTO are reinitialized and marked as
IORESOURCE_UNSET by pnp_clean_resource_table() in these cases:
- before we attempt to assign resources automatically,
- if we fail to assign resources automatically,
- after disabling a device
IORESOURCE_DISABLED
Set by pnp_assign_{io,mem,etc}() when automatic assignment fails.
Also set by PNPBIOS and PNPACPI for:
- invalid IRQs or GSI registration failures
- invalid DMA channels
- I/O ports above 0x10000
- mem ranges with negative length
After this patch, there is no pnp_resource_table, and the resource list
entries use the flags like this:
IORESOURCE_UNSET
This flag is no longer used in PNP. Instead of keeping
IORESOURCE_UNSET entries in the resource list, we remove
entries from the list and free them.
IORESOURCE_AUTO
No change in meaning: it still means the resource was assigned
automatically by pnp_assign_{port,mem,etc}(), but these functions
now set the bit explicitly.
We still "clean" a device's resource list in the same places,
but rather than reinitializing IORESOURCE_AUTO entries, we
just remove them from the list.
Note that IORESOURCE_AUTO entries are always at the end of the
list, so removing them doesn't reorder other list entries.
This is because non-IORESOURCE_AUTO entries are added by the
ISAPNP, PNPBIOS, or PNPACPI "get resources" methods and by the
sysfs "set" command. In each of these cases, we completely free
the resource list first.
IORESOURCE_DISABLED
In addition to the cases where we used to set this flag, ISAPNP now
adds an IORESOURCE_DISABLED resource when it reads a configuration
register with a "disabled" value.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
2008-06-28 05:56:57 +07:00
|
|
|
struct list_head resources;
|
PNP: convert resource options to single linked list
ISAPNP, PNPBIOS, and ACPI describe the "possible resource settings" of
a device, i.e., the possibilities an OS bus driver has when it assigns
I/O port, MMIO, and other resources to the device.
PNP used to maintain this "possible resource setting" information in
one independent option structure and a list of dependent option
structures for each device. Each of these option structures had lists
of I/O, memory, IRQ, and DMA resources, for example:
dev
independent options
ind-io0 -> ind-io1 ...
ind-mem0 -> ind-mem1 ...
...
dependent option set 0
dep0-io0 -> dep0-io1 ...
dep0-mem0 -> dep0-mem1 ...
...
dependent option set 1
dep1-io0 -> dep1-io1 ...
dep1-mem0 -> dep1-mem1 ...
...
...
This data structure was designed for ISAPNP, where the OS configures
device resource settings by writing directly to configuration
registers. The OS can write the registers in arbitrary order much
like it writes PCI BARs.
However, for PNPBIOS and ACPI devices, the OS uses firmware interfaces
that perform device configuration, and it is important to pass the
desired settings to those interfaces in the correct order. The OS
learns the correct order by using firmware interfaces that return the
"current resource settings" and "possible resource settings," but the
option structures above doesn't store the ordering information.
This patch replaces the independent and dependent lists with a single
list of options. For example, a device might have possible resource
settings like this:
dev
options
ind-io0 -> dep0-io0 -> dep1->io0 -> ind-io1 ...
All the possible settings are in the same list, in the order they
come from the firmware "possible resource settings" list. Each entry
is tagged with an independent/dependent flag. Dependent entries also
have a "set number" and an optional priority value. All dependent
entries must be assigned from the same set. For example, the OS can
use all the entries from dependent set 0, or all the entries from
dependent set 1, but it cannot mix entries from set 0 with entries
from set 1.
Prior to this patch PNP didn't keep track of the order of this list,
and it assigned all independent options first, then all dependent
ones. Using the example above, that resulted in a "desired
configuration" list like this:
ind->io0 -> ind->io1 -> depN-io0 ...
instead of the list the firmware expects, which looks like this:
ind->io0 -> depN-io0 -> ind-io1 ...
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Rene Herman <rene.herman@gmail.com>
Signed-off-by: Len Brown <len.brown@intel.com>
2008-06-28 05:57:17 +07:00
|
|
|
struct list_head options;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
char name[PNP_NAME_LEN]; /* contains a human-readable name */
|
2007-07-27 00:41:21 +07:00
|
|
|
int flags; /* used by protocols */
|
2005-04-17 05:20:36 +07:00
|
|
|
struct proc_dir_entry *procent; /* device entry in /proc/bus/isapnp */
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define global_to_pnp_dev(n) list_entry(n, struct pnp_dev, global_list)
|
|
|
|
#define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list)
|
|
|
|
#define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list)
|
|
|
|
#define to_pnp_dev(n) container_of(n, struct pnp_dev, dev)
|
|
|
|
#define pnp_for_each_dev(dev) \
|
|
|
|
for((dev) = global_to_pnp_dev(pnp_global.next); \
|
|
|
|
(dev) != global_to_pnp_dev(&pnp_global); \
|
|
|
|
(dev) = global_to_pnp_dev((dev)->global_list.next))
|
|
|
|
#define card_for_each_dev(card,dev) \
|
|
|
|
for((dev) = card_to_pnp_dev((card)->devices.next); \
|
|
|
|
(dev) != card_to_pnp_dev(&(card)->devices); \
|
|
|
|
(dev) = card_to_pnp_dev((dev)->card_list.next))
|
|
|
|
#define pnp_dev_name(dev) (dev)->name
|
|
|
|
|
2007-07-27 00:41:20 +07:00
|
|
|
static inline void *pnp_get_drvdata(struct pnp_dev *pdev)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
return dev_get_drvdata(&pdev->dev);
|
|
|
|
}
|
|
|
|
|
2007-07-27 00:41:20 +07:00
|
|
|
static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
dev_set_drvdata(&pdev->dev, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pnp_fixup {
|
|
|
|
char id[7];
|
2007-07-27 00:41:20 +07:00
|
|
|
void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* config parameters */
|
|
|
|
#define PNP_CONFIG_NORMAL 0x0001
|
|
|
|
#define PNP_CONFIG_FORCE 0x0002 /* disables validity checking */
|
|
|
|
|
|
|
|
/* capabilities */
|
|
|
|
#define PNP_READ 0x0001
|
|
|
|
#define PNP_WRITE 0x0002
|
|
|
|
#define PNP_DISABLE 0x0004
|
|
|
|
#define PNP_CONFIGURABLE 0x0008
|
|
|
|
#define PNP_REMOVABLE 0x0010
|
2015-01-22 23:50:24 +07:00
|
|
|
#define PNP_CONSOLE 0x0020
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-10-17 13:31:09 +07:00
|
|
|
#define pnp_can_read(dev) (((dev)->protocol->get) && \
|
2005-04-17 05:20:36 +07:00
|
|
|
((dev)->capabilities & PNP_READ))
|
2007-10-17 13:31:09 +07:00
|
|
|
#define pnp_can_write(dev) (((dev)->protocol->set) && \
|
2005-04-17 05:20:36 +07:00
|
|
|
((dev)->capabilities & PNP_WRITE))
|
2015-01-22 23:50:24 +07:00
|
|
|
#define pnp_can_disable(dev) (((dev)->protocol->disable) && \
|
|
|
|
((dev)->capabilities & PNP_DISABLE) && \
|
|
|
|
(!((dev)->capabilities & PNP_CONSOLE) || \
|
|
|
|
console_suspend_enabled))
|
2005-04-17 05:20:36 +07:00
|
|
|
#define pnp_can_configure(dev) ((!(dev)->active) && \
|
|
|
|
((dev)->capabilities & PNP_CONFIGURABLE))
|
2015-01-22 23:50:24 +07:00
|
|
|
#define pnp_can_suspend(dev) (((dev)->protocol->suspend) && \
|
|
|
|
(!((dev)->capabilities & PNP_CONSOLE) || \
|
|
|
|
console_suspend_enabled))
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_ISAPNP
|
|
|
|
extern struct pnp_protocol isapnp_protocol;
|
|
|
|
#define pnp_device_is_isapnp(dev) ((dev)->protocol == (&isapnp_protocol))
|
|
|
|
#else
|
|
|
|
#define pnp_device_is_isapnp(dev) 0
|
|
|
|
#endif
|
2008-02-06 16:40:04 +07:00
|
|
|
extern struct mutex pnp_res_mutex;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_PNPBIOS
|
|
|
|
extern struct pnp_protocol pnpbios_protocol;
|
|
|
|
#define pnp_device_is_pnpbios(dev) ((dev)->protocol == (&pnpbios_protocol))
|
|
|
|
#else
|
|
|
|
#define pnp_device_is_pnpbios(dev) 0
|
|
|
|
#endif
|
|
|
|
|
2009-11-18 07:05:19 +07:00
|
|
|
#ifdef CONFIG_PNPACPI
|
|
|
|
extern struct pnp_protocol pnpacpi_protocol;
|
|
|
|
|
|
|
|
static inline struct acpi_device *pnp_acpi_device(struct pnp_dev *dev)
|
|
|
|
{
|
|
|
|
if (dev->protocol == &pnpacpi_protocol)
|
|
|
|
return dev->data;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define pnp_acpi_device(dev) 0
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* status */
|
|
|
|
#define PNP_READY 0x0000
|
|
|
|
#define PNP_ATTACHED 0x0001
|
|
|
|
#define PNP_BUSY 0x0002
|
|
|
|
#define PNP_FAULTY 0x0004
|
|
|
|
|
|
|
|
/* isapnp specific macros */
|
|
|
|
|
|
|
|
#define isapnp_card_number(dev) ((dev)->card ? (dev)->card->number : -1)
|
|
|
|
#define isapnp_csn_number(dev) ((dev)->number)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Driver Management
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct pnp_id {
|
|
|
|
char id[PNP_ID_LEN];
|
2007-07-27 00:41:20 +07:00
|
|
|
struct pnp_id *next;
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pnp_driver {
|
2007-07-27 00:41:20 +07:00
|
|
|
char *name;
|
2005-04-17 05:20:36 +07:00
|
|
|
const struct pnp_device_id *id_table;
|
|
|
|
unsigned int flags;
|
2007-07-27 00:41:21 +07:00
|
|
|
int (*probe) (struct pnp_dev *dev, const struct pnp_device_id *dev_id);
|
|
|
|
void (*remove) (struct pnp_dev *dev);
|
2009-09-22 07:04:52 +07:00
|
|
|
void (*shutdown) (struct pnp_dev *dev);
|
2007-07-27 00:41:21 +07:00
|
|
|
int (*suspend) (struct pnp_dev *dev, pm_message_t state);
|
|
|
|
int (*resume) (struct pnp_dev *dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
struct device_driver driver;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_pnp_driver(drv) container_of(drv, struct pnp_driver, driver)
|
|
|
|
|
|
|
|
struct pnp_card_driver {
|
|
|
|
struct list_head global_list;
|
2007-07-27 00:41:20 +07:00
|
|
|
char *name;
|
2005-04-17 05:20:36 +07:00
|
|
|
const struct pnp_card_device_id *id_table;
|
|
|
|
unsigned int flags;
|
2007-07-27 00:41:21 +07:00
|
|
|
int (*probe) (struct pnp_card_link *card,
|
|
|
|
const struct pnp_card_device_id *card_id);
|
|
|
|
void (*remove) (struct pnp_card_link *card);
|
|
|
|
int (*suspend) (struct pnp_card_link *card, pm_message_t state);
|
|
|
|
int (*resume) (struct pnp_card_link *card);
|
2005-04-17 05:20:36 +07:00
|
|
|
struct pnp_driver link;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_pnp_card_driver(drv) container_of(drv, struct pnp_card_driver, link)
|
|
|
|
|
|
|
|
/* pnp driver flags */
|
|
|
|
#define PNP_DRIVER_RES_DO_NOT_CHANGE 0x0001 /* do not change the state of the device */
|
|
|
|
#define PNP_DRIVER_RES_DISABLE 0x0003 /* ensure the device is disabled */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Protocol Management
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct pnp_protocol {
|
2007-07-27 00:41:20 +07:00
|
|
|
struct list_head protocol_list;
|
|
|
|
char *name;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* resource control functions */
|
2008-04-29 05:34:05 +07:00
|
|
|
int (*get) (struct pnp_dev *dev);
|
|
|
|
int (*set) (struct pnp_dev *dev);
|
2007-07-27 00:41:21 +07:00
|
|
|
int (*disable) (struct pnp_dev *dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-07-20 09:03:20 +07:00
|
|
|
/* protocol specific suspend/resume */
|
2010-06-30 03:49:24 +07:00
|
|
|
bool (*can_wakeup) (struct pnp_dev *dev);
|
2007-07-27 00:41:20 +07:00
|
|
|
int (*suspend) (struct pnp_dev * dev, pm_message_t state);
|
|
|
|
int (*resume) (struct pnp_dev * dev);
|
2007-07-20 09:03:20 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* used by pnp layer only (look but don't touch) */
|
2007-07-27 00:41:20 +07:00
|
|
|
unsigned char number; /* protocol number */
|
|
|
|
struct device dev; /* link to driver model */
|
|
|
|
struct list_head cards;
|
|
|
|
struct list_head devices;
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list)
|
|
|
|
#define protocol_for_each_card(protocol,card) \
|
|
|
|
for((card) = protocol_to_pnp_card((protocol)->cards.next); \
|
|
|
|
(card) != protocol_to_pnp_card(&(protocol)->cards); \
|
|
|
|
(card) = protocol_to_pnp_card((card)->protocol_list.next))
|
|
|
|
#define protocol_for_each_dev(protocol,dev) \
|
|
|
|
for((dev) = protocol_to_pnp_dev((protocol)->devices.next); \
|
|
|
|
(dev) != protocol_to_pnp_dev(&(protocol)->devices); \
|
|
|
|
(dev) = protocol_to_pnp_dev((dev)->protocol_list.next))
|
|
|
|
|
2007-02-10 16:45:13 +07:00
|
|
|
extern struct bus_type pnp_bus_type;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#if defined(CONFIG_PNP)
|
|
|
|
|
|
|
|
/* device management */
|
|
|
|
int pnp_device_attach(struct pnp_dev *pnp_dev);
|
|
|
|
void pnp_device_detach(struct pnp_dev *pnp_dev);
|
|
|
|
extern struct list_head pnp_global;
|
2007-05-08 14:35:54 +07:00
|
|
|
extern int pnp_platform_devices;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* multidevice card support */
|
2007-07-27 00:41:20 +07:00
|
|
|
struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
|
|
|
|
const char *id, struct pnp_dev *from);
|
|
|
|
void pnp_release_card_device(struct pnp_dev *dev);
|
|
|
|
int pnp_register_card_driver(struct pnp_card_driver *drv);
|
|
|
|
void pnp_unregister_card_driver(struct pnp_card_driver *drv);
|
2005-04-17 05:20:36 +07:00
|
|
|
extern struct list_head pnp_cards;
|
|
|
|
|
|
|
|
/* resource management */
|
2008-06-28 05:57:01 +07:00
|
|
|
int pnp_possible_config(struct pnp_dev *dev, int type, resource_size_t base,
|
|
|
|
resource_size_t size);
|
2005-04-17 05:20:36 +07:00
|
|
|
int pnp_auto_config_dev(struct pnp_dev *dev);
|
2005-11-29 15:09:32 +07:00
|
|
|
int pnp_start_dev(struct pnp_dev *dev);
|
|
|
|
int pnp_stop_dev(struct pnp_dev *dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
int pnp_activate_dev(struct pnp_dev *dev);
|
|
|
|
int pnp_disable_dev(struct pnp_dev *dev);
|
2009-06-05 21:37:23 +07:00
|
|
|
int pnp_range_reserved(resource_size_t start, resource_size_t end);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* protocol helpers */
|
2007-07-27 00:41:20 +07:00
|
|
|
int pnp_is_active(struct pnp_dev *dev);
|
|
|
|
int compare_pnp_id(struct pnp_id *pos, const char *id);
|
2005-04-17 05:20:36 +07:00
|
|
|
int pnp_register_driver(struct pnp_driver *drv);
|
|
|
|
void pnp_unregister_driver(struct pnp_driver *drv);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* device management */
|
2007-07-27 00:41:21 +07:00
|
|
|
static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; }
|
|
|
|
static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { }
|
2007-07-27 00:41:20 +07:00
|
|
|
|
2007-05-08 14:35:54 +07:00
|
|
|
#define pnp_platform_devices 0
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* multidevice card support */
|
2007-07-27 00:41:21 +07:00
|
|
|
static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; }
|
|
|
|
static inline void pnp_release_card_device(struct pnp_dev *dev) { }
|
|
|
|
static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; }
|
|
|
|
static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { }
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* resource management */
|
2008-06-28 05:57:01 +07:00
|
|
|
static inline int pnp_possible_config(struct pnp_dev *dev, int type,
|
|
|
|
resource_size_t base,
|
|
|
|
resource_size_t size) { return 0; }
|
2007-07-27 00:41:21 +07:00
|
|
|
static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
|
|
|
|
static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; }
|
|
|
|
static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; }
|
|
|
|
static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; }
|
|
|
|
static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; }
|
2009-06-05 21:37:23 +07:00
|
|
|
static inline int pnp_range_reserved(resource_size_t start, resource_size_t end) { return 0;}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* protocol helpers */
|
2007-07-27 00:41:21 +07:00
|
|
|
static inline int pnp_is_active(struct pnp_dev *dev) { return 0; }
|
|
|
|
static inline int compare_pnp_id(struct pnp_id *pos, const char *id) { return -ENODEV; }
|
|
|
|
static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; }
|
|
|
|
static inline void pnp_unregister_driver(struct pnp_driver *drv) { }
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#endif /* CONFIG_PNP */
|
|
|
|
|
2015-03-17 03:46:30 +07:00
|
|
|
/**
|
|
|
|
* module_pnp_driver() - Helper macro for registering a PnP driver
|
|
|
|
* @__pnp_driver: pnp_driver struct
|
|
|
|
*
|
|
|
|
* Helper macro for PnP drivers which do not do anything special in module
|
|
|
|
* init/exit. This eliminates a lot of boilerplate. Each module may only
|
|
|
|
* use this macro once, and calling it replaces module_init() and module_exit()
|
|
|
|
*/
|
|
|
|
#define module_pnp_driver(__pnp_driver) \
|
|
|
|
module_driver(__pnp_driver, pnp_register_driver, \
|
|
|
|
pnp_unregister_driver)
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif /* _LINUX_PNP_H */
|