blob: e3fa9a2d9a3d3a2a9124bd334c54632aeb760f94 [file] [log] [blame]
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -06001/*
2 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
3 * Bjorn Helgaas <bjorn.helgaas@hp.com>
4 */
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006extern spinlock_t pnp_lock;
7void *pnp_alloc(long size);
Bjorn Helgaas62cfb292008-04-28 16:34:40 -06008
9int pnp_register_protocol(struct pnp_protocol *protocol);
10void pnp_unregister_protocol(struct pnp_protocol *protocol);
11
Bjorn Helgaas25eb8462008-04-28 16:33:53 -060012#define PNP_EISA_ID_MASK 0x7fffffff
13void pnp_eisa_id_to_string(u32 id, char *str);
Bjorn Helgaasbda1e4e2008-04-28 16:33:54 -060014struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
Bjorn Helgaas6bf2aab2008-04-28 16:33:58 -060015struct pnp_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
Bjorn Helgaas62cfb292008-04-28 16:34:40 -060016
17int pnp_add_device(struct pnp_dev *dev);
Bjorn Helgaas772defc2008-04-28 16:33:52 -060018struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070019int pnp_interface_attach_device(struct pnp_dev *dev);
Bjorn Helgaas62cfb292008-04-28 16:34:40 -060020
21int pnp_add_card(struct pnp_card *card);
22struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id);
23void pnp_remove_card(struct pnp_card *card);
24int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
25void pnp_remove_card_device(struct pnp_dev *dev);
26
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060027struct pnp_port {
Bjorn Helgaas169aaff2008-06-27 16:57:06 -060028 resource_size_t min; /* min base number */
29 resource_size_t max; /* max base number */
30 resource_size_t align; /* align boundary */
31 resource_size_t size; /* size of range */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060032 unsigned char flags; /* port flags */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060033};
34
35#define PNP_IRQ_NR 256
Bjorn Helgaas7aefff52008-06-27 16:57:05 -060036typedef struct { DECLARE_BITMAP(bits, PNP_IRQ_NR); } pnp_irq_mask_t;
37
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060038struct pnp_irq {
Bjorn Helgaas7aefff52008-06-27 16:57:05 -060039 pnp_irq_mask_t map; /* bitmap for IRQ lines */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060040 unsigned char flags; /* IRQ flags */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060041};
42
43struct pnp_dma {
44 unsigned char map; /* bitmask for DMA channels */
45 unsigned char flags; /* DMA flags */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060046};
47
48struct pnp_mem {
Bjorn Helgaas169aaff2008-06-27 16:57:06 -060049 resource_size_t min; /* min base number */
50 resource_size_t max; /* max base number */
51 resource_size_t align; /* align boundary */
52 resource_size_t size; /* size of range */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060053 unsigned char flags; /* memory flags */
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060054};
55
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060056#define PNP_OPTION_DEPENDENT 0x80000000
57#define PNP_OPTION_SET_MASK 0xffff
58#define PNP_OPTION_SET_SHIFT 12
59#define PNP_OPTION_PRIORITY_MASK 0xfff
60#define PNP_OPTION_PRIORITY_SHIFT 0
61
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060062#define PNP_RES_PRIORITY_PREFERRED 0
63#define PNP_RES_PRIORITY_ACCEPTABLE 1
64#define PNP_RES_PRIORITY_FUNCTIONAL 2
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060065#define PNP_RES_PRIORITY_INVALID PNP_OPTION_PRIORITY_MASK
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060066
67struct pnp_option {
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060068 struct list_head list;
69 unsigned int flags; /* independent/dependent, set, priority */
70
71 unsigned long type; /* IORESOURCE_{IO,MEM,IRQ,DMA} */
72 union {
73 struct pnp_port port;
74 struct pnp_irq irq;
75 struct pnp_dma dma;
76 struct pnp_mem mem;
77 } u;
Bjorn Helgaasa1802c42008-06-27 16:57:04 -060078};
79
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060080int pnp_register_irq_resource(struct pnp_dev *dev, unsigned int option_flags,
Bjorn Helgaasc2275362008-06-27 16:57:11 -060081 pnp_irq_mask_t *map, unsigned char flags);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060082int pnp_register_dma_resource(struct pnp_dev *dev, unsigned int option_flags,
Bjorn Helgaasc2275362008-06-27 16:57:11 -060083 unsigned char map, unsigned char flags);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060084int pnp_register_port_resource(struct pnp_dev *dev, unsigned int option_flags,
Bjorn Helgaasc2275362008-06-27 16:57:11 -060085 resource_size_t min, resource_size_t max,
86 resource_size_t align, resource_size_t size,
87 unsigned char flags);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060088int pnp_register_mem_resource(struct pnp_dev *dev, unsigned int option_flags,
Bjorn Helgaasc2275362008-06-27 16:57:11 -060089 resource_size_t min, resource_size_t max,
90 resource_size_t align, resource_size_t size,
91 unsigned char flags);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060092
93static inline int pnp_option_is_dependent(struct pnp_option *option)
94{
95 return option->flags & PNP_OPTION_DEPENDENT ? 1 : 0;
96}
97
98static inline unsigned int pnp_option_set(struct pnp_option *option)
99{
100 return (option->flags >> PNP_OPTION_SET_SHIFT) & PNP_OPTION_SET_MASK;
101}
102
103static inline unsigned int pnp_option_priority(struct pnp_option *option)
104{
105 return (option->flags >> PNP_OPTION_PRIORITY_SHIFT) &
106 PNP_OPTION_PRIORITY_MASK;
107}
108
109static inline unsigned int pnp_new_dependent_set(struct pnp_dev *dev,
110 int priority)
111{
112 unsigned int flags;
113
114 if (priority > PNP_RES_PRIORITY_FUNCTIONAL) {
115 dev_warn(&dev->dev, "invalid dependent option priority %d "
116 "clipped to %d", priority,
117 PNP_RES_PRIORITY_INVALID);
118 priority = PNP_RES_PRIORITY_INVALID;
119 }
120
121 flags = PNP_OPTION_DEPENDENT |
122 ((dev->num_dependent_sets & PNP_OPTION_SET_MASK) <<
123 PNP_OPTION_SET_SHIFT) |
124 ((priority & PNP_OPTION_PRIORITY_MASK) <<
125 PNP_OPTION_PRIORITY_SHIFT);
126
127 dev->num_dependent_sets++;
128
129 return flags;
130}
131
132char *pnp_option_priority_name(struct pnp_option *option);
133void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option);
134
Bjorn Helgaas62cfb292008-04-28 16:34:40 -0600135void pnp_init_resources(struct pnp_dev *dev);
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137void pnp_fixup_device(struct pnp_dev *dev);
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600138void pnp_free_options(struct pnp_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139int __pnp_add_device(struct pnp_dev *dev);
140void __pnp_remove_device(struct pnp_dev *dev);
141
Bjorn Helgaasf5d94ff2008-04-28 16:34:22 -0600142int pnp_check_port(struct pnp_dev *dev, struct resource *res);
143int pnp_check_mem(struct pnp_dev *dev, struct resource *res);
144int pnp_check_irq(struct pnp_dev *dev, struct resource *res);
145int pnp_check_dma(struct pnp_dev *dev, struct resource *res);
Bjorn Helgaas81b5c752008-04-28 16:34:08 -0600146
Bjorn Helgaas9fdee4e2008-06-27 16:56:55 -0600147char *pnp_resource_type_name(struct resource *res);
Bjorn Helgaas81b5c752008-04-28 16:34:08 -0600148void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc);
Bjorn Helgaasd948a8d2008-04-28 16:34:13 -0600149
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600150void pnp_free_resources(struct pnp_dev *dev);
Bjorn Helgaas940e98d2008-06-27 16:56:54 -0600151int pnp_resource_type(struct resource *res);
Bjorn Helgaas02d83b52008-04-28 16:34:28 -0600152
Bjorn Helgaas784f01d2008-04-28 16:34:30 -0600153struct pnp_resource {
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600154 struct list_head list;
Bjorn Helgaas784f01d2008-04-28 16:34:30 -0600155 struct resource res;
156};
157
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600158void pnp_free_resource(struct pnp_resource *pnp_res);
Bjorn Helgaasdbddd032008-04-28 16:34:34 -0600159
160struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
161 int flags);
Bjorn Helgaasdc16f5f2008-04-28 16:34:35 -0600162struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
163 int flags);
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600164struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
165 resource_size_t start,
166 resource_size_t end, int flags);
Bjorn Helgaasd6180f32008-04-28 16:34:37 -0600167struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
168 resource_size_t start,
169 resource_size_t end, int flags);