diff options
Diffstat (limited to 'include/linux/pnp.h')
-rw-r--r-- | include/linux/pnp.h | 146 |
1 files changed, 78 insertions, 68 deletions
diff --git a/include/linux/pnp.h b/include/linux/pnp.h index 63b128d512fb..1ce54b63085d 100644 --- a/include/linux/pnp.h +++ b/include/linux/pnp.h | |||
@@ -1,6 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * Linux Plug and Play Support | 2 | * Linux Plug and Play Support |
3 | * Copyright by Adam Belay <ambx1@neo.rr.com> | 3 | * Copyright by Adam Belay <ambx1@neo.rr.com> |
4 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. | ||
5 | * Bjorn Helgaas <bjorn.helgaas@hp.com> | ||
4 | */ | 6 | */ |
5 | 7 | ||
6 | #ifndef _LINUX_PNP_H | 8 | #ifndef _LINUX_PNP_H |
@@ -15,7 +17,6 @@ | |||
15 | 17 | ||
16 | struct pnp_protocol; | 18 | struct pnp_protocol; |
17 | struct pnp_dev; | 19 | struct pnp_dev; |
18 | struct pnp_resource_table; | ||
19 | 20 | ||
20 | /* | 21 | /* |
21 | * Resource Management | 22 | * Resource Management |
@@ -24,7 +25,14 @@ struct resource *pnp_get_resource(struct pnp_dev *, unsigned int, unsigned int); | |||
24 | 25 | ||
25 | static inline int pnp_resource_valid(struct resource *res) | 26 | static inline int pnp_resource_valid(struct resource *res) |
26 | { | 27 | { |
27 | if (res && !(res->flags & IORESOURCE_UNSET)) | 28 | if (res) |
29 | return 1; | ||
30 | return 0; | ||
31 | } | ||
32 | |||
33 | static inline int pnp_resource_enabled(struct resource *res) | ||
34 | { | ||
35 | if (res && !(res->flags & IORESOURCE_DISABLED)) | ||
28 | return 1; | 36 | return 1; |
29 | return 0; | 37 | return 0; |
30 | } | 38 | } |
@@ -40,19 +48,31 @@ static inline resource_size_t pnp_resource_len(struct resource *res) | |||
40 | static inline resource_size_t pnp_port_start(struct pnp_dev *dev, | 48 | static inline resource_size_t pnp_port_start(struct pnp_dev *dev, |
41 | unsigned int bar) | 49 | unsigned int bar) |
42 | { | 50 | { |
43 | return pnp_get_resource(dev, IORESOURCE_IO, bar)->start; | 51 | struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar); |
52 | |||
53 | if (pnp_resource_valid(res)) | ||
54 | return res->start; | ||
55 | return 0; | ||
44 | } | 56 | } |
45 | 57 | ||
46 | static inline resource_size_t pnp_port_end(struct pnp_dev *dev, | 58 | static inline resource_size_t pnp_port_end(struct pnp_dev *dev, |
47 | unsigned int bar) | 59 | unsigned int bar) |
48 | { | 60 | { |
49 | return pnp_get_resource(dev, IORESOURCE_IO, bar)->end; | 61 | struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar); |
62 | |||
63 | if (pnp_resource_valid(res)) | ||
64 | return res->end; | ||
65 | return 0; | ||
50 | } | 66 | } |
51 | 67 | ||
52 | static inline unsigned long pnp_port_flags(struct pnp_dev *dev, | 68 | static inline unsigned long pnp_port_flags(struct pnp_dev *dev, |
53 | unsigned int bar) | 69 | unsigned int bar) |
54 | { | 70 | { |
55 | return pnp_get_resource(dev, IORESOURCE_IO, bar)->flags; | 71 | struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar); |
72 | |||
73 | if (pnp_resource_valid(res)) | ||
74 | return res->flags; | ||
75 | return IORESOURCE_IO | IORESOURCE_AUTO; | ||
56 | } | 76 | } |
57 | 77 | ||
58 | static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar) | 78 | static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar) |
@@ -63,25 +83,41 @@ static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar) | |||
63 | static inline resource_size_t pnp_port_len(struct pnp_dev *dev, | 83 | static inline resource_size_t pnp_port_len(struct pnp_dev *dev, |
64 | unsigned int bar) | 84 | unsigned int bar) |
65 | { | 85 | { |
66 | return pnp_resource_len(pnp_get_resource(dev, IORESOURCE_IO, bar)); | 86 | struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar); |
87 | |||
88 | if (pnp_resource_valid(res)) | ||
89 | return pnp_resource_len(res); | ||
90 | return 0; | ||
67 | } | 91 | } |
68 | 92 | ||
69 | 93 | ||
70 | static inline resource_size_t pnp_mem_start(struct pnp_dev *dev, | 94 | static inline resource_size_t pnp_mem_start(struct pnp_dev *dev, |
71 | unsigned int bar) | 95 | unsigned int bar) |
72 | { | 96 | { |
73 | return pnp_get_resource(dev, IORESOURCE_MEM, bar)->start; | 97 | struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar); |
98 | |||
99 | if (pnp_resource_valid(res)) | ||
100 | return res->start; | ||
101 | return 0; | ||
74 | } | 102 | } |
75 | 103 | ||
76 | static inline resource_size_t pnp_mem_end(struct pnp_dev *dev, | 104 | static inline resource_size_t pnp_mem_end(struct pnp_dev *dev, |
77 | unsigned int bar) | 105 | unsigned int bar) |
78 | { | 106 | { |
79 | return pnp_get_resource(dev, IORESOURCE_MEM, bar)->end; | 107 | struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar); |
108 | |||
109 | if (pnp_resource_valid(res)) | ||
110 | return res->end; | ||
111 | return 0; | ||
80 | } | 112 | } |
81 | 113 | ||
82 | static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar) | 114 | static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar) |
83 | { | 115 | { |
84 | return pnp_get_resource(dev, IORESOURCE_MEM, bar)->flags; | 116 | struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar); |
117 | |||
118 | if (pnp_resource_valid(res)) | ||
119 | return res->flags; | ||
120 | return IORESOURCE_MEM | IORESOURCE_AUTO; | ||
85 | } | 121 | } |
86 | 122 | ||
87 | static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar) | 123 | static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar) |
@@ -92,18 +128,30 @@ static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar) | |||
92 | static inline resource_size_t pnp_mem_len(struct pnp_dev *dev, | 128 | static inline resource_size_t pnp_mem_len(struct pnp_dev *dev, |
93 | unsigned int bar) | 129 | unsigned int bar) |
94 | { | 130 | { |
95 | return pnp_resource_len(pnp_get_resource(dev, IORESOURCE_MEM, bar)); | 131 | struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar); |
132 | |||
133 | if (pnp_resource_valid(res)) | ||
134 | return pnp_resource_len(res); | ||
135 | return 0; | ||
96 | } | 136 | } |
97 | 137 | ||
98 | 138 | ||
99 | static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar) | 139 | static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar) |
100 | { | 140 | { |
101 | return pnp_get_resource(dev, IORESOURCE_IRQ, bar)->start; | 141 | struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar); |
142 | |||
143 | if (pnp_resource_valid(res)) | ||
144 | return res->start; | ||
145 | return -1; | ||
102 | } | 146 | } |
103 | 147 | ||
104 | static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar) | 148 | static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar) |
105 | { | 149 | { |
106 | return pnp_get_resource(dev, IORESOURCE_IRQ, bar)->flags; | 150 | struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar); |
151 | |||
152 | if (pnp_resource_valid(res)) | ||
153 | return res->flags; | ||
154 | return IORESOURCE_IRQ | IORESOURCE_AUTO; | ||
107 | } | 155 | } |
108 | 156 | ||
109 | static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar) | 157 | static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar) |
@@ -114,12 +162,20 @@ static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar) | |||
114 | 162 | ||
115 | static inline resource_size_t pnp_dma(struct pnp_dev *dev, unsigned int bar) | 163 | static inline resource_size_t pnp_dma(struct pnp_dev *dev, unsigned int bar) |
116 | { | 164 | { |
117 | return pnp_get_resource(dev, IORESOURCE_DMA, bar)->start; | 165 | struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar); |
166 | |||
167 | if (pnp_resource_valid(res)) | ||
168 | return res->start; | ||
169 | return -1; | ||
118 | } | 170 | } |
119 | 171 | ||
120 | static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar) | 172 | static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar) |
121 | { | 173 | { |
122 | return pnp_get_resource(dev, IORESOURCE_DMA, bar)->flags; | 174 | struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar); |
175 | |||
176 | if (pnp_resource_valid(res)) | ||
177 | return res->flags; | ||
178 | return IORESOURCE_DMA | IORESOURCE_AUTO; | ||
123 | } | 179 | } |
124 | 180 | ||
125 | static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar) | 181 | static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar) |
@@ -128,57 +184,6 @@ static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar) | |||
128 | } | 184 | } |
129 | 185 | ||
130 | 186 | ||
131 | #define PNP_PORT_FLAG_16BITADDR (1<<0) | ||
132 | #define PNP_PORT_FLAG_FIXED (1<<1) | ||
133 | |||
134 | struct pnp_port { | ||
135 | unsigned short min; /* min base number */ | ||
136 | unsigned short max; /* max base number */ | ||
137 | unsigned char align; /* align boundary */ | ||
138 | unsigned char size; /* size of range */ | ||
139 | unsigned char flags; /* port flags */ | ||
140 | unsigned char pad; /* pad */ | ||
141 | struct pnp_port *next; /* next port */ | ||
142 | }; | ||
143 | |||
144 | #define PNP_IRQ_NR 256 | ||
145 | struct pnp_irq { | ||
146 | DECLARE_BITMAP(map, PNP_IRQ_NR); /* bitmask for IRQ lines */ | ||
147 | unsigned char flags; /* IRQ flags */ | ||
148 | unsigned char pad; /* pad */ | ||
149 | struct pnp_irq *next; /* next IRQ */ | ||
150 | }; | ||
151 | |||
152 | struct pnp_dma { | ||
153 | unsigned char map; /* bitmask for DMA channels */ | ||
154 | unsigned char flags; /* DMA flags */ | ||
155 | struct pnp_dma *next; /* next port */ | ||
156 | }; | ||
157 | |||
158 | struct pnp_mem { | ||
159 | unsigned int min; /* min base number */ | ||
160 | unsigned int max; /* max base number */ | ||
161 | unsigned int align; /* align boundary */ | ||
162 | unsigned int size; /* size of range */ | ||
163 | unsigned char flags; /* memory flags */ | ||
164 | unsigned char pad; /* pad */ | ||
165 | struct pnp_mem *next; /* next memory resource */ | ||
166 | }; | ||
167 | |||
168 | #define PNP_RES_PRIORITY_PREFERRED 0 | ||
169 | #define PNP_RES_PRIORITY_ACCEPTABLE 1 | ||
170 | #define PNP_RES_PRIORITY_FUNCTIONAL 2 | ||
171 | #define PNP_RES_PRIORITY_INVALID 65535 | ||
172 | |||
173 | struct pnp_option { | ||
174 | unsigned short priority; /* priority */ | ||
175 | struct pnp_port *port; /* first port */ | ||
176 | struct pnp_irq *irq; /* first IRQ */ | ||
177 | struct pnp_dma *dma; /* first DMA */ | ||
178 | struct pnp_mem *mem; /* first memory resource */ | ||
179 | struct pnp_option *next; /* used to chain dependent resources */ | ||
180 | }; | ||
181 | |||
182 | /* | 187 | /* |
183 | * Device Management | 188 | * Device Management |
184 | */ | 189 | */ |
@@ -246,9 +251,9 @@ struct pnp_dev { | |||
246 | 251 | ||
247 | int active; | 252 | int active; |
248 | int capabilities; | 253 | int capabilities; |
249 | struct pnp_option *independent; | 254 | unsigned int num_dependent_sets; |
250 | struct pnp_option *dependent; | 255 | struct list_head resources; |
251 | struct pnp_resource_table *res; | 256 | struct list_head options; |
252 | 257 | ||
253 | char name[PNP_NAME_LEN]; /* contains a human-readable name */ | 258 | char name[PNP_NAME_LEN]; /* contains a human-readable name */ |
254 | int flags; /* used by protocols */ | 259 | int flags; /* used by protocols */ |
@@ -425,6 +430,8 @@ void pnp_unregister_card_driver(struct pnp_card_driver *drv); | |||
425 | extern struct list_head pnp_cards; | 430 | extern struct list_head pnp_cards; |
426 | 431 | ||
427 | /* resource management */ | 432 | /* resource management */ |
433 | int pnp_possible_config(struct pnp_dev *dev, int type, resource_size_t base, | ||
434 | resource_size_t size); | ||
428 | int pnp_auto_config_dev(struct pnp_dev *dev); | 435 | int pnp_auto_config_dev(struct pnp_dev *dev); |
429 | int pnp_start_dev(struct pnp_dev *dev); | 436 | int pnp_start_dev(struct pnp_dev *dev); |
430 | int pnp_stop_dev(struct pnp_dev *dev); | 437 | int pnp_stop_dev(struct pnp_dev *dev); |
@@ -452,6 +459,9 @@ static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return | |||
452 | static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { } | 459 | static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { } |
453 | 460 | ||
454 | /* resource management */ | 461 | /* resource management */ |
462 | static inline int pnp_possible_config(struct pnp_dev *dev, int type, | ||
463 | resource_size_t base, | ||
464 | resource_size_t size) { return 0; } | ||
455 | static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; } | 465 | static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; } |
456 | static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; } | 466 | static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; } |
457 | static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; } | 467 | static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; } |