mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-19 10:14:23 +08:00
1f32ca31e7
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>
170 lines
5.3 KiB
C
170 lines
5.3 KiB
C
/*
|
|
* Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
|
|
* Bjorn Helgaas <bjorn.helgaas@hp.com>
|
|
*/
|
|
|
|
extern spinlock_t pnp_lock;
|
|
void *pnp_alloc(long size);
|
|
|
|
int pnp_register_protocol(struct pnp_protocol *protocol);
|
|
void pnp_unregister_protocol(struct pnp_protocol *protocol);
|
|
|
|
#define PNP_EISA_ID_MASK 0x7fffffff
|
|
void pnp_eisa_id_to_string(u32 id, char *str);
|
|
struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
|
|
struct pnp_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
|
|
|
|
int pnp_add_device(struct pnp_dev *dev);
|
|
struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
|
|
int pnp_interface_attach_device(struct pnp_dev *dev);
|
|
|
|
int pnp_add_card(struct pnp_card *card);
|
|
struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id);
|
|
void pnp_remove_card(struct pnp_card *card);
|
|
int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
|
|
void pnp_remove_card_device(struct pnp_dev *dev);
|
|
|
|
struct pnp_port {
|
|
resource_size_t min; /* min base number */
|
|
resource_size_t max; /* max base number */
|
|
resource_size_t align; /* align boundary */
|
|
resource_size_t size; /* size of range */
|
|
unsigned char flags; /* port flags */
|
|
};
|
|
|
|
#define PNP_IRQ_NR 256
|
|
typedef struct { DECLARE_BITMAP(bits, PNP_IRQ_NR); } pnp_irq_mask_t;
|
|
|
|
struct pnp_irq {
|
|
pnp_irq_mask_t map; /* bitmap for IRQ lines */
|
|
unsigned char flags; /* IRQ flags */
|
|
};
|
|
|
|
struct pnp_dma {
|
|
unsigned char map; /* bitmask for DMA channels */
|
|
unsigned char flags; /* DMA flags */
|
|
};
|
|
|
|
struct pnp_mem {
|
|
resource_size_t min; /* min base number */
|
|
resource_size_t max; /* max base number */
|
|
resource_size_t align; /* align boundary */
|
|
resource_size_t size; /* size of range */
|
|
unsigned char flags; /* memory flags */
|
|
};
|
|
|
|
#define PNP_OPTION_DEPENDENT 0x80000000
|
|
#define PNP_OPTION_SET_MASK 0xffff
|
|
#define PNP_OPTION_SET_SHIFT 12
|
|
#define PNP_OPTION_PRIORITY_MASK 0xfff
|
|
#define PNP_OPTION_PRIORITY_SHIFT 0
|
|
|
|
#define PNP_RES_PRIORITY_PREFERRED 0
|
|
#define PNP_RES_PRIORITY_ACCEPTABLE 1
|
|
#define PNP_RES_PRIORITY_FUNCTIONAL 2
|
|
#define PNP_RES_PRIORITY_INVALID PNP_OPTION_PRIORITY_MASK
|
|
|
|
struct pnp_option {
|
|
struct list_head list;
|
|
unsigned int flags; /* independent/dependent, set, priority */
|
|
|
|
unsigned long type; /* IORESOURCE_{IO,MEM,IRQ,DMA} */
|
|
union {
|
|
struct pnp_port port;
|
|
struct pnp_irq irq;
|
|
struct pnp_dma dma;
|
|
struct pnp_mem mem;
|
|
} u;
|
|
};
|
|
|
|
int pnp_register_irq_resource(struct pnp_dev *dev, unsigned int option_flags,
|
|
pnp_irq_mask_t *map, unsigned char flags);
|
|
int pnp_register_dma_resource(struct pnp_dev *dev, unsigned int option_flags,
|
|
unsigned char map, unsigned char flags);
|
|
int pnp_register_port_resource(struct pnp_dev *dev, unsigned int option_flags,
|
|
resource_size_t min, resource_size_t max,
|
|
resource_size_t align, resource_size_t size,
|
|
unsigned char flags);
|
|
int pnp_register_mem_resource(struct pnp_dev *dev, unsigned int option_flags,
|
|
resource_size_t min, resource_size_t max,
|
|
resource_size_t align, resource_size_t size,
|
|
unsigned char flags);
|
|
|
|
static inline int pnp_option_is_dependent(struct pnp_option *option)
|
|
{
|
|
return option->flags & PNP_OPTION_DEPENDENT ? 1 : 0;
|
|
}
|
|
|
|
static inline unsigned int pnp_option_set(struct pnp_option *option)
|
|
{
|
|
return (option->flags >> PNP_OPTION_SET_SHIFT) & PNP_OPTION_SET_MASK;
|
|
}
|
|
|
|
static inline unsigned int pnp_option_priority(struct pnp_option *option)
|
|
{
|
|
return (option->flags >> PNP_OPTION_PRIORITY_SHIFT) &
|
|
PNP_OPTION_PRIORITY_MASK;
|
|
}
|
|
|
|
static inline unsigned int pnp_new_dependent_set(struct pnp_dev *dev,
|
|
int priority)
|
|
{
|
|
unsigned int flags;
|
|
|
|
if (priority > PNP_RES_PRIORITY_FUNCTIONAL) {
|
|
dev_warn(&dev->dev, "invalid dependent option priority %d "
|
|
"clipped to %d", priority,
|
|
PNP_RES_PRIORITY_INVALID);
|
|
priority = PNP_RES_PRIORITY_INVALID;
|
|
}
|
|
|
|
flags = PNP_OPTION_DEPENDENT |
|
|
((dev->num_dependent_sets & PNP_OPTION_SET_MASK) <<
|
|
PNP_OPTION_SET_SHIFT) |
|
|
((priority & PNP_OPTION_PRIORITY_MASK) <<
|
|
PNP_OPTION_PRIORITY_SHIFT);
|
|
|
|
dev->num_dependent_sets++;
|
|
|
|
return flags;
|
|
}
|
|
|
|
char *pnp_option_priority_name(struct pnp_option *option);
|
|
void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option);
|
|
|
|
void pnp_init_resources(struct pnp_dev *dev);
|
|
|
|
void pnp_fixup_device(struct pnp_dev *dev);
|
|
void pnp_free_options(struct pnp_dev *dev);
|
|
int __pnp_add_device(struct pnp_dev *dev);
|
|
void __pnp_remove_device(struct pnp_dev *dev);
|
|
|
|
int pnp_check_port(struct pnp_dev *dev, struct resource *res);
|
|
int pnp_check_mem(struct pnp_dev *dev, struct resource *res);
|
|
int pnp_check_irq(struct pnp_dev *dev, struct resource *res);
|
|
int pnp_check_dma(struct pnp_dev *dev, struct resource *res);
|
|
|
|
char *pnp_resource_type_name(struct resource *res);
|
|
void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc);
|
|
|
|
void pnp_free_resources(struct pnp_dev *dev);
|
|
int pnp_resource_type(struct resource *res);
|
|
|
|
struct pnp_resource {
|
|
struct list_head list;
|
|
struct resource res;
|
|
};
|
|
|
|
void pnp_free_resource(struct pnp_resource *pnp_res);
|
|
|
|
struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
|
|
int flags);
|
|
struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
|
|
int flags);
|
|
struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
|
|
resource_size_t start,
|
|
resource_size_t end, int flags);
|
|
struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
|
|
resource_size_t start,
|
|
resource_size_t end, int flags);
|