aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2005-07-30 13:15:57 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-30 13:15:57 -0400
commit6d1d07e41a1de478a0da3cc14b4a8054ef09931c (patch)
treedb7802272fd8aff185a6ecc29ea78c1e3005783b
parentd7a465b4740806e4ee34061ad455595b2fa9fad5 (diff)
parentadbedd34244e2b054557002817f979a9b004a405 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/lenb/to-linus
-rw-r--r--arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c7
-rw-r--r--arch/i386/pci/acpi.c1
-rw-r--r--arch/i386/pci/common.c6
-rw-r--r--arch/i386/pci/irq.c1
-rw-r--r--arch/i386/pci/pci.h1
-rw-r--r--drivers/acpi/ec.c893
-rw-r--r--drivers/acpi/pci_irq.c85
-rw-r--r--drivers/acpi/pci_link.c103
-rw-r--r--drivers/acpi/processor_idle.c31
-rw-r--r--drivers/net/sk98lin/skge.c63
-rw-r--r--include/acpi/acpi_drivers.h3
-rw-r--r--include/linux/acpi.h4
-rw-r--r--sound/pci/intel8x0.c7
13 files changed, 972 insertions, 233 deletions
diff --git a/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c b/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c
index 963e17aa205d..60a9e54dd20e 100644
--- a/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c
+++ b/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c
@@ -442,6 +442,13 @@ acpi_cpufreq_cpu_init (
442 (u32) data->acpi_data.states[i].transition_latency); 442 (u32) data->acpi_data.states[i].transition_latency);
443 443
444 cpufreq_frequency_table_get_attr(data->freq_table, policy->cpu); 444 cpufreq_frequency_table_get_attr(data->freq_table, policy->cpu);
445
446 /*
447 * the first call to ->target() should result in us actually
448 * writing something to the appropriate registers.
449 */
450 data->resume = 1;
451
445 return (result); 452 return (result);
446 453
447 err_freqfree: 454 err_freqfree:
diff --git a/arch/i386/pci/acpi.c b/arch/i386/pci/acpi.c
index 2db65ec45dc3..42913f43feb0 100644
--- a/arch/i386/pci/acpi.c
+++ b/arch/i386/pci/acpi.c
@@ -30,6 +30,7 @@ static int __init pci_acpi_init(void)
30 acpi_irq_penalty_init(); 30 acpi_irq_penalty_init();
31 pcibios_scanned++; 31 pcibios_scanned++;
32 pcibios_enable_irq = acpi_pci_irq_enable; 32 pcibios_enable_irq = acpi_pci_irq_enable;
33 pcibios_disable_irq = acpi_pci_irq_disable;
33 34
34 if (pci_routeirq) { 35 if (pci_routeirq) {
35 /* 36 /*
diff --git a/arch/i386/pci/common.c b/arch/i386/pci/common.c
index 70bcd53451f6..ade5bc57c34c 100644
--- a/arch/i386/pci/common.c
+++ b/arch/i386/pci/common.c
@@ -254,3 +254,9 @@ int pcibios_enable_device(struct pci_dev *dev, int mask)
254 254
255 return pcibios_enable_irq(dev); 255 return pcibios_enable_irq(dev);
256} 256}
257
258void pcibios_disable_device (struct pci_dev *dev)
259{
260 if (pcibios_disable_irq)
261 pcibios_disable_irq(dev);
262}
diff --git a/arch/i386/pci/irq.c b/arch/i386/pci/irq.c
index d291fb7f1357..86348b68fda1 100644
--- a/arch/i386/pci/irq.c
+++ b/arch/i386/pci/irq.c
@@ -56,6 +56,7 @@ struct irq_router_handler {
56}; 56};
57 57
58int (*pcibios_enable_irq)(struct pci_dev *dev) = NULL; 58int (*pcibios_enable_irq)(struct pci_dev *dev) = NULL;
59void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
59 60
60/* 61/*
61 * Check passed address for the PCI IRQ Routing Table signature 62 * Check passed address for the PCI IRQ Routing Table signature
diff --git a/arch/i386/pci/pci.h b/arch/i386/pci/pci.h
index a80f0f55ff51..127d53ad16be 100644
--- a/arch/i386/pci/pci.h
+++ b/arch/i386/pci/pci.h
@@ -73,3 +73,4 @@ extern int pcibios_scanned;
73extern spinlock_t pci_config_lock; 73extern spinlock_t pci_config_lock;
74 74
75extern int (*pcibios_enable_irq)(struct pci_dev *dev); 75extern int (*pcibios_enable_irq)(struct pci_dev *dev);
76extern void (*pcibios_disable_irq)(struct pci_dev *dev);
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index fca4140a50a9..2dadb7f63269 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -59,76 +59,185 @@ ACPI_MODULE_NAME ("acpi_ec")
59#define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */ 59#define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */
60#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ 60#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
61 61
62#define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
63#define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */
64
62#define ACPI_EC_COMMAND_READ 0x80 65#define ACPI_EC_COMMAND_READ 0x80
63#define ACPI_EC_COMMAND_WRITE 0x81 66#define ACPI_EC_COMMAND_WRITE 0x81
64#define ACPI_EC_BURST_ENABLE 0x82 67#define ACPI_EC_BURST_ENABLE 0x82
65#define ACPI_EC_BURST_DISABLE 0x83 68#define ACPI_EC_BURST_DISABLE 0x83
66#define ACPI_EC_COMMAND_QUERY 0x84 69#define ACPI_EC_COMMAND_QUERY 0x84
67 70
68static int acpi_ec_add (struct acpi_device *device); 71#define EC_POLLING 0xFF
72#define EC_BURST 0x00
73
74
69static int acpi_ec_remove (struct acpi_device *device, int type); 75static int acpi_ec_remove (struct acpi_device *device, int type);
70static int acpi_ec_start (struct acpi_device *device); 76static int acpi_ec_start (struct acpi_device *device);
71static int acpi_ec_stop (struct acpi_device *device, int type); 77static int acpi_ec_stop (struct acpi_device *device, int type);
78static int acpi_ec_burst_add ( struct acpi_device *device);
72 79
73static struct acpi_driver acpi_ec_driver = { 80static struct acpi_driver acpi_ec_driver = {
74 .name = ACPI_EC_DRIVER_NAME, 81 .name = ACPI_EC_DRIVER_NAME,
75 .class = ACPI_EC_CLASS, 82 .class = ACPI_EC_CLASS,
76 .ids = ACPI_EC_HID, 83 .ids = ACPI_EC_HID,
77 .ops = { 84 .ops = {
78 .add = acpi_ec_add, 85 .add = acpi_ec_burst_add,
79 .remove = acpi_ec_remove, 86 .remove = acpi_ec_remove,
80 .start = acpi_ec_start, 87 .start = acpi_ec_start,
81 .stop = acpi_ec_stop, 88 .stop = acpi_ec_stop,
82 }, 89 },
83}; 90};
84 91union acpi_ec {
85struct acpi_ec { 92 struct {
86 acpi_handle handle; 93 u32 mode;
87 unsigned long uid; 94 acpi_handle handle;
88 unsigned long gpe_bit; 95 unsigned long uid;
89 struct acpi_generic_address status_addr; 96 unsigned long gpe_bit;
90 struct acpi_generic_address command_addr; 97 struct acpi_generic_address status_addr;
91 struct acpi_generic_address data_addr; 98 struct acpi_generic_address command_addr;
92 unsigned long global_lock; 99 struct acpi_generic_address data_addr;
93 unsigned int expect_event; 100 unsigned long global_lock;
94 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort*/ 101 } common;
95 atomic_t pending_gpe; 102
96 struct semaphore sem; 103 struct {
97 wait_queue_head_t wait; 104 u32 mode;
105 acpi_handle handle;
106 unsigned long uid;
107 unsigned long gpe_bit;
108 struct acpi_generic_address status_addr;
109 struct acpi_generic_address command_addr;
110 struct acpi_generic_address data_addr;
111 unsigned long global_lock;
112 unsigned int expect_event;
113 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort*/
114 atomic_t pending_gpe;
115 struct semaphore sem;
116 wait_queue_head_t wait;
117 }burst;
118
119 struct {
120 u32 mode;
121 acpi_handle handle;
122 unsigned long uid;
123 unsigned long gpe_bit;
124 struct acpi_generic_address status_addr;
125 struct acpi_generic_address command_addr;
126 struct acpi_generic_address data_addr;
127 unsigned long global_lock;
128 spinlock_t lock;
129 }polling;
98}; 130};
99 131
132static int acpi_ec_polling_wait ( union acpi_ec *ec, u8 event);
133static int acpi_ec_burst_wait(union acpi_ec *ec, unsigned int event);
134static int acpi_ec_polling_read ( union acpi_ec *ec, u8 address, u32 *data);
135static int acpi_ec_burst_read( union acpi_ec *ec, u8 address, u32 *data);
136static int acpi_ec_polling_write ( union acpi_ec *ec, u8 address, u8 data);
137static int acpi_ec_burst_write ( union acpi_ec *ec, u8 address, u8 data);
138static int acpi_ec_polling_query ( union acpi_ec *ec, u32 *data);
139static int acpi_ec_burst_query ( union acpi_ec *ec, u32 *data);
140static void acpi_ec_gpe_polling_query ( void *ec_cxt);
141static void acpi_ec_gpe_burst_query ( void *ec_cxt);
142static u32 acpi_ec_gpe_polling_handler ( void *data);
143static u32 acpi_ec_gpe_burst_handler ( void *data);
144static acpi_status __init
145acpi_fake_ecdt_polling_callback (
146 acpi_handle handle,
147 u32 Level,
148 void *context,
149 void **retval);
150
151static acpi_status __init
152acpi_fake_ecdt_burst_callback (
153 acpi_handle handle,
154 u32 Level,
155 void *context,
156 void **retval);
157
158static int __init
159acpi_ec_polling_get_real_ecdt(void);
160static int __init
161acpi_ec_burst_get_real_ecdt(void);
100/* If we find an EC via the ECDT, we need to keep a ptr to its context */ 162/* If we find an EC via the ECDT, we need to keep a ptr to its context */
101static struct acpi_ec *ec_ecdt; 163static union acpi_ec *ec_ecdt;
102 164
103/* External interfaces use first EC only, so remember */ 165/* External interfaces use first EC only, so remember */
104static struct acpi_device *first_ec; 166static struct acpi_device *first_ec;
167static int acpi_ec_polling_mode;
105 168
106/* -------------------------------------------------------------------------- 169/* --------------------------------------------------------------------------
107 Transaction Management 170 Transaction Management
108 -------------------------------------------------------------------------- */ 171 -------------------------------------------------------------------------- */
109 172
110static inline u32 acpi_ec_read_status(struct acpi_ec *ec) 173static inline u32 acpi_ec_read_status(union acpi_ec *ec)
111{ 174{
112 u32 status = 0; 175 u32 status = 0;
113 176
114 acpi_hw_low_level_read(8, &status, &ec->status_addr); 177 acpi_hw_low_level_read(8, &status, &ec->common.status_addr);
115 return status; 178 return status;
116} 179}
117 180
118static int acpi_ec_wait(struct acpi_ec *ec, unsigned int event) 181static int
182acpi_ec_wait (
183 union acpi_ec *ec,
184 u8 event)
185{
186 if (acpi_ec_polling_mode)
187 return acpi_ec_polling_wait (ec, event);
188 else
189 return acpi_ec_burst_wait (ec, event);
190}
191
192static int
193acpi_ec_polling_wait (
194 union acpi_ec *ec,
195 u8 event)
196{
197 u32 acpi_ec_status = 0;
198 u32 i = ACPI_EC_UDELAY_COUNT;
199
200 if (!ec)
201 return -EINVAL;
202
203 /* Poll the EC status register waiting for the event to occur. */
204 switch (event) {
205 case ACPI_EC_EVENT_OBF:
206 do {
207 acpi_hw_low_level_read(8, &acpi_ec_status, &ec->common.status_addr);
208 if (acpi_ec_status & ACPI_EC_FLAG_OBF)
209 return 0;
210 udelay(ACPI_EC_UDELAY);
211 } while (--i>0);
212 break;
213 case ACPI_EC_EVENT_IBE:
214 do {
215 acpi_hw_low_level_read(8, &acpi_ec_status, &ec->common.status_addr);
216 if (!(acpi_ec_status & ACPI_EC_FLAG_IBF))
217 return 0;
218 udelay(ACPI_EC_UDELAY);
219 } while (--i>0);
220 break;
221 default:
222 return -EINVAL;
223 }
224
225 return -ETIME;
226}
227static int acpi_ec_burst_wait(union acpi_ec *ec, unsigned int event)
119{ 228{
120 int result = 0; 229 int result = 0;
121 230
122 ACPI_FUNCTION_TRACE("acpi_ec_wait"); 231 ACPI_FUNCTION_TRACE("acpi_ec_wait");
123 232
124 ec->expect_event = event; 233 ec->burst.expect_event = event;
125 smp_mb(); 234 smp_mb();
126 235
127 result = wait_event_interruptible_timeout(ec->wait, 236 result = wait_event_interruptible_timeout(ec->burst.wait,
128 !ec->expect_event, 237 !ec->burst.expect_event,
129 msecs_to_jiffies(ACPI_EC_DELAY)); 238 msecs_to_jiffies(ACPI_EC_DELAY));
130 239
131 ec->expect_event = 0; 240 ec->burst.expect_event = 0;
132 smp_mb(); 241 smp_mb();
133 242
134 if (result < 0){ 243 if (result < 0){
@@ -160,7 +269,7 @@ static int acpi_ec_wait(struct acpi_ec *ec, unsigned int event)
160 269
161static int 270static int
162acpi_ec_enter_burst_mode ( 271acpi_ec_enter_burst_mode (
163 struct acpi_ec *ec) 272 union acpi_ec *ec)
164{ 273{
165 u32 tmp = 0; 274 u32 tmp = 0;
166 int status = 0; 275 int status = 0;
@@ -170,43 +279,43 @@ acpi_ec_enter_burst_mode (
170 status = acpi_ec_read_status(ec); 279 status = acpi_ec_read_status(ec);
171 if (status != -EINVAL && 280 if (status != -EINVAL &&
172 !(status & ACPI_EC_FLAG_BURST)){ 281 !(status & ACPI_EC_FLAG_BURST)){
173 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr); 282 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->common.command_addr);
174 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 283 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
175 if (status){ 284 if (status){
176 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 285 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
177 return_VALUE(-EINVAL); 286 return_VALUE(-EINVAL);
178 } 287 }
179 acpi_hw_low_level_read(8, &tmp, &ec->data_addr); 288 acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr);
180 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 289 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
181 if(tmp != 0x90 ) {/* Burst ACK byte*/ 290 if(tmp != 0x90 ) {/* Burst ACK byte*/
182 return_VALUE(-EINVAL); 291 return_VALUE(-EINVAL);
183 } 292 }
184 } 293 }
185 294
186 atomic_set(&ec->leaving_burst , 0); 295 atomic_set(&ec->burst.leaving_burst , 0);
187 return_VALUE(0); 296 return_VALUE(0);
188} 297}
189 298
190static int 299static int
191acpi_ec_leave_burst_mode ( 300acpi_ec_leave_burst_mode (
192 struct acpi_ec *ec) 301 union acpi_ec *ec)
193{ 302{
194 int status =0; 303 int status =0;
195 304
196 ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode"); 305 ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode");
197 306
198 atomic_set(&ec->leaving_burst , 1); 307 atomic_set(&ec->burst.leaving_burst , 1);
199 status = acpi_ec_read_status(ec); 308 status = acpi_ec_read_status(ec);
200 if (status != -EINVAL && 309 if (status != -EINVAL &&
201 (status & ACPI_EC_FLAG_BURST)){ 310 (status & ACPI_EC_FLAG_BURST)){
202 acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->command_addr); 311 acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->common.command_addr);
203 status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF); 312 status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF);
204 if (status){ 313 if (status){
205 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 314 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
206 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->wait fail\n")); 315 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->wait fail\n"));
207 return_VALUE(-EINVAL); 316 return_VALUE(-EINVAL);
208 } 317 }
209 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 318 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
210 status = acpi_ec_read_status(ec); 319 status = acpi_ec_read_status(ec);
211 } 320 }
212 321
@@ -215,7 +324,131 @@ acpi_ec_leave_burst_mode (
215 324
216static int 325static int
217acpi_ec_read ( 326acpi_ec_read (
218 struct acpi_ec *ec, 327 union acpi_ec *ec,
328 u8 address,
329 u32 *data)
330{
331 if (acpi_ec_polling_mode)
332 return acpi_ec_polling_read(ec, address, data);
333 else
334 return acpi_ec_burst_read(ec, address, data);
335}
336static int
337acpi_ec_write (
338 union acpi_ec *ec,
339 u8 address,
340 u8 data)
341{
342 if (acpi_ec_polling_mode)
343 return acpi_ec_polling_write(ec, address, data);
344 else
345 return acpi_ec_burst_write(ec, address, data);
346}
347static int
348acpi_ec_polling_read (
349 union acpi_ec *ec,
350 u8 address,
351 u32 *data)
352{
353 acpi_status status = AE_OK;
354 int result = 0;
355 unsigned long flags = 0;
356 u32 glk = 0;
357
358 ACPI_FUNCTION_TRACE("acpi_ec_read");
359
360 if (!ec || !data)
361 return_VALUE(-EINVAL);
362
363 *data = 0;
364
365 if (ec->common.global_lock) {
366 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
367 if (ACPI_FAILURE(status))
368 return_VALUE(-ENODEV);
369 }
370
371 spin_lock_irqsave(&ec->polling.lock, flags);
372
373 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->common.command_addr);
374 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
375 if (result)
376 goto end;
377
378 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
379 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
380 if (result)
381 goto end;
382
383 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
384
385 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n",
386 *data, address));
387
388end:
389 spin_unlock_irqrestore(&ec->polling.lock, flags);
390
391 if (ec->common.global_lock)
392 acpi_release_global_lock(glk);
393
394 return_VALUE(result);
395}
396
397
398static int
399acpi_ec_polling_write (
400 union acpi_ec *ec,
401 u8 address,
402 u8 data)
403{
404 int result = 0;
405 acpi_status status = AE_OK;
406 unsigned long flags = 0;
407 u32 glk = 0;
408
409 ACPI_FUNCTION_TRACE("acpi_ec_write");
410
411 if (!ec)
412 return_VALUE(-EINVAL);
413
414 if (ec->common.global_lock) {
415 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
416 if (ACPI_FAILURE(status))
417 return_VALUE(-ENODEV);
418 }
419
420 spin_lock_irqsave(&ec->polling.lock, flags);
421
422 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->common.command_addr);
423 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
424 if (result)
425 goto end;
426
427 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
428 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
429 if (result)
430 goto end;
431
432 acpi_hw_low_level_write(8, data, &ec->common.data_addr);
433 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
434 if (result)
435 goto end;
436
437 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n",
438 data, address));
439
440end:
441 spin_unlock_irqrestore(&ec->polling.lock, flags);
442
443 if (ec->common.global_lock)
444 acpi_release_global_lock(glk);
445
446 return_VALUE(result);
447}
448
449static int
450acpi_ec_burst_read (
451 union acpi_ec *ec,
219 u8 address, 452 u8 address,
220 u32 *data) 453 u32 *data)
221{ 454{
@@ -230,51 +463,51 @@ acpi_ec_read (
230retry: 463retry:
231 *data = 0; 464 *data = 0;
232 465
233 if (ec->global_lock) { 466 if (ec->common.global_lock) {
234 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 467 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
235 if (ACPI_FAILURE(status)) 468 if (ACPI_FAILURE(status))
236 return_VALUE(-ENODEV); 469 return_VALUE(-ENODEV);
237 } 470 }
238 471
239 WARN_ON(in_interrupt()); 472 WARN_ON(in_interrupt());
240 down(&ec->sem); 473 down(&ec->burst.sem);
241 474
242 if(acpi_ec_enter_burst_mode(ec)) 475 if(acpi_ec_enter_burst_mode(ec))
243 goto end; 476 goto end;
244 477
245 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->command_addr); 478 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->common.command_addr);
246 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 479 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
247 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 480 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
248 if (status) { 481 if (status) {
249 goto end; 482 goto end;
250 } 483 }
251 484
252 acpi_hw_low_level_write(8, address, &ec->data_addr); 485 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
253 status= acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 486 status= acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
254 if (status){ 487 if (status){
255 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 488 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
256 goto end; 489 goto end;
257 } 490 }
258 491
259 acpi_hw_low_level_read(8, data, &ec->data_addr); 492 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
260 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 493 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
261 494
262 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n", 495 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n",
263 *data, address)); 496 *data, address));
264 497
265end: 498end:
266 acpi_ec_leave_burst_mode(ec); 499 acpi_ec_leave_burst_mode(ec);
267 up(&ec->sem); 500 up(&ec->burst.sem);
268 501
269 if (ec->global_lock) 502 if (ec->common.global_lock)
270 acpi_release_global_lock(glk); 503 acpi_release_global_lock(glk);
271 504
272 if(atomic_read(&ec->leaving_burst) == 2){ 505 if(atomic_read(&ec->burst.leaving_burst) == 2){
273 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); 506 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
274 while(atomic_read(&ec->pending_gpe)){ 507 while(atomic_read(&ec->burst.pending_gpe)){
275 msleep(1); 508 msleep(1);
276 } 509 }
277 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 510 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
278 goto retry; 511 goto retry;
279 } 512 }
280 513
@@ -283,8 +516,8 @@ end:
283 516
284 517
285static int 518static int
286acpi_ec_write ( 519acpi_ec_burst_write (
287 struct acpi_ec *ec, 520 union acpi_ec *ec,
288 u8 address, 521 u8 address,
289 u8 data) 522 u8 data)
290{ 523{
@@ -297,14 +530,14 @@ acpi_ec_write (
297 if (!ec) 530 if (!ec)
298 return_VALUE(-EINVAL); 531 return_VALUE(-EINVAL);
299retry: 532retry:
300 if (ec->global_lock) { 533 if (ec->common.global_lock) {
301 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 534 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
302 if (ACPI_FAILURE(status)) 535 if (ACPI_FAILURE(status))
303 return_VALUE(-ENODEV); 536 return_VALUE(-ENODEV);
304 } 537 }
305 538
306 WARN_ON(in_interrupt()); 539 WARN_ON(in_interrupt());
307 down(&ec->sem); 540 down(&ec->burst.sem);
308 541
309 if(acpi_ec_enter_burst_mode(ec)) 542 if(acpi_ec_enter_burst_mode(ec))
310 goto end; 543 goto end;
@@ -312,33 +545,33 @@ retry:
312 status = acpi_ec_read_status(ec); 545 status = acpi_ec_read_status(ec);
313 if (status != -EINVAL && 546 if (status != -EINVAL &&
314 !(status & ACPI_EC_FLAG_BURST)){ 547 !(status & ACPI_EC_FLAG_BURST)){
315 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr); 548 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->common.command_addr);
316 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 549 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
317 if (status) 550 if (status)
318 goto end; 551 goto end;
319 acpi_hw_low_level_read(8, &tmp, &ec->data_addr); 552 acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr);
320 if(tmp != 0x90 ) /* Burst ACK byte*/ 553 if(tmp != 0x90 ) /* Burst ACK byte*/
321 goto end; 554 goto end;
322 } 555 }
323 /*Now we are in burst mode*/ 556 /*Now we are in burst mode*/
324 557
325 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->command_addr); 558 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->common.command_addr);
326 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 559 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
327 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 560 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
328 if (status){ 561 if (status){
329 goto end; 562 goto end;
330 } 563 }
331 564
332 acpi_hw_low_level_write(8, address, &ec->data_addr); 565 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
333 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 566 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
334 if (status){ 567 if (status){
335 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 568 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
336 goto end; 569 goto end;
337 } 570 }
338 571
339 acpi_hw_low_level_write(8, data, &ec->data_addr); 572 acpi_hw_low_level_write(8, data, &ec->common.data_addr);
340 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 573 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
341 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 574 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
342 if (status) 575 if (status)
343 goto end; 576 goto end;
344 577
@@ -347,17 +580,17 @@ retry:
347 580
348end: 581end:
349 acpi_ec_leave_burst_mode(ec); 582 acpi_ec_leave_burst_mode(ec);
350 up(&ec->sem); 583 up(&ec->burst.sem);
351 584
352 if (ec->global_lock) 585 if (ec->common.global_lock)
353 acpi_release_global_lock(glk); 586 acpi_release_global_lock(glk);
354 587
355 if(atomic_read(&ec->leaving_burst) == 2){ 588 if(atomic_read(&ec->burst.leaving_burst) == 2){
356 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); 589 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
357 while(atomic_read(&ec->pending_gpe)){ 590 while(atomic_read(&ec->burst.pending_gpe)){
358 msleep(1); 591 msleep(1);
359 } 592 }
360 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 593 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
361 goto retry; 594 goto retry;
362 } 595 }
363 596
@@ -370,7 +603,7 @@ end:
370int 603int
371ec_read(u8 addr, u8 *val) 604ec_read(u8 addr, u8 *val)
372{ 605{
373 struct acpi_ec *ec; 606 union acpi_ec *ec;
374 int err; 607 int err;
375 u32 temp_data; 608 u32 temp_data;
376 609
@@ -393,7 +626,7 @@ EXPORT_SYMBOL(ec_read);
393int 626int
394ec_write(u8 addr, u8 val) 627ec_write(u8 addr, u8 val)
395{ 628{
396 struct acpi_ec *ec; 629 union acpi_ec *ec;
397 int err; 630 int err;
398 631
399 if (!first_ec) 632 if (!first_ec)
@@ -407,10 +640,66 @@ ec_write(u8 addr, u8 val)
407} 640}
408EXPORT_SYMBOL(ec_write); 641EXPORT_SYMBOL(ec_write);
409 642
410
411static int 643static int
412acpi_ec_query ( 644acpi_ec_query (
413 struct acpi_ec *ec, 645 union acpi_ec *ec,
646 u32 *data)
647{
648 if (acpi_ec_polling_mode)
649 return acpi_ec_polling_query(ec, data);
650 else
651 return acpi_ec_burst_query(ec, data);
652}
653static int
654acpi_ec_polling_query (
655 union acpi_ec *ec,
656 u32 *data)
657{
658 int result = 0;
659 acpi_status status = AE_OK;
660 unsigned long flags = 0;
661 u32 glk = 0;
662
663 ACPI_FUNCTION_TRACE("acpi_ec_query");
664
665 if (!ec || !data)
666 return_VALUE(-EINVAL);
667
668 *data = 0;
669
670 if (ec->common.global_lock) {
671 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
672 if (ACPI_FAILURE(status))
673 return_VALUE(-ENODEV);
674 }
675
676 /*
677 * Query the EC to find out which _Qxx method we need to evaluate.
678 * Note that successful completion of the query causes the ACPI_EC_SCI
679 * bit to be cleared (and thus clearing the interrupt source).
680 */
681 spin_lock_irqsave(&ec->polling.lock, flags);
682
683 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->common.command_addr);
684 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
685 if (result)
686 goto end;
687
688 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
689 if (!*data)
690 result = -ENODATA;
691
692end:
693 spin_unlock_irqrestore(&ec->polling.lock, flags);
694
695 if (ec->common.global_lock)
696 acpi_release_global_lock(glk);
697
698 return_VALUE(result);
699}
700static int
701acpi_ec_burst_query (
702 union acpi_ec *ec,
414 u32 *data) 703 u32 *data)
415{ 704{
416 int status = 0; 705 int status = 0;
@@ -422,13 +711,13 @@ acpi_ec_query (
422 return_VALUE(-EINVAL); 711 return_VALUE(-EINVAL);
423 *data = 0; 712 *data = 0;
424 713
425 if (ec->global_lock) { 714 if (ec->common.global_lock) {
426 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 715 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
427 if (ACPI_FAILURE(status)) 716 if (ACPI_FAILURE(status))
428 return_VALUE(-ENODEV); 717 return_VALUE(-ENODEV);
429 } 718 }
430 719
431 down(&ec->sem); 720 down(&ec->burst.sem);
432 if(acpi_ec_enter_burst_mode(ec)) 721 if(acpi_ec_enter_burst_mode(ec))
433 goto end; 722 goto end;
434 /* 723 /*
@@ -436,28 +725,28 @@ acpi_ec_query (
436 * Note that successful completion of the query causes the ACPI_EC_SCI 725 * Note that successful completion of the query causes the ACPI_EC_SCI
437 * bit to be cleared (and thus clearing the interrupt source). 726 * bit to be cleared (and thus clearing the interrupt source).
438 */ 727 */
439 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->command_addr); 728 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->common.command_addr);
440 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 729 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
441 if (status){ 730 if (status){
442 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 731 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
443 goto end; 732 goto end;
444 } 733 }
445 734
446 acpi_hw_low_level_read(8, data, &ec->data_addr); 735 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
447 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 736 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
448 if (!*data) 737 if (!*data)
449 status = -ENODATA; 738 status = -ENODATA;
450 739
451end: 740end:
452 acpi_ec_leave_burst_mode(ec); 741 acpi_ec_leave_burst_mode(ec);
453 up(&ec->sem); 742 up(&ec->burst.sem);
454 743
455 if (ec->global_lock) 744 if (ec->common.global_lock)
456 acpi_release_global_lock(glk); 745 acpi_release_global_lock(glk);
457 746
458 if(atomic_read(&ec->leaving_burst) == 2){ 747 if(atomic_read(&ec->burst.leaving_burst) == 2){
459 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); 748 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
460 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 749 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
461 status = -ENODATA; 750 status = -ENODATA;
462 } 751 }
463 return_VALUE(status); 752 return_VALUE(status);
@@ -468,7 +757,7 @@ end:
468 Event Management 757 Event Management
469 -------------------------------------------------------------------------- */ 758 -------------------------------------------------------------------------- */
470 759
471struct acpi_ec_query_data { 760union acpi_ec_query_data {
472 acpi_handle handle; 761 acpi_handle handle;
473 u8 data; 762 u8 data;
474}; 763};
@@ -477,7 +766,59 @@ static void
477acpi_ec_gpe_query ( 766acpi_ec_gpe_query (
478 void *ec_cxt) 767 void *ec_cxt)
479{ 768{
480 struct acpi_ec *ec = (struct acpi_ec *) ec_cxt; 769 if (acpi_ec_polling_mode)
770 acpi_ec_gpe_polling_query(ec_cxt);
771 else
772 acpi_ec_gpe_burst_query(ec_cxt);
773}
774
775static void
776acpi_ec_gpe_polling_query (
777 void *ec_cxt)
778{
779 union acpi_ec *ec = (union acpi_ec *) ec_cxt;
780 u32 value = 0;
781 unsigned long flags = 0;
782 static char object_name[5] = {'_','Q','0','0','\0'};
783 const char hex[] = {'0','1','2','3','4','5','6','7',
784 '8','9','A','B','C','D','E','F'};
785
786 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
787
788 if (!ec_cxt)
789 goto end;
790
791 spin_lock_irqsave(&ec->polling.lock, flags);
792 acpi_hw_low_level_read(8, &value, &ec->common.command_addr);
793 spin_unlock_irqrestore(&ec->polling.lock, flags);
794
795 /* TBD: Implement asynch events!
796 * NOTE: All we care about are EC-SCI's. Other EC events are
797 * handled via polling (yuck!). This is because some systems
798 * treat EC-SCIs as level (versus EDGE!) triggered, preventing
799 * a purely interrupt-driven approach (grumble, grumble).
800 */
801 if (!(value & ACPI_EC_FLAG_SCI))
802 goto end;
803
804 if (acpi_ec_query(ec, &value))
805 goto end;
806
807 object_name[2] = hex[((value >> 4) & 0x0F)];
808 object_name[3] = hex[(value & 0x0F)];
809
810 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name));
811
812 acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL);
813
814end:
815 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
816}
817static void
818acpi_ec_gpe_burst_query (
819 void *ec_cxt)
820{
821 union acpi_ec *ec = (union acpi_ec *) ec_cxt;
481 u32 value; 822 u32 value;
482 int result = -ENODATA; 823 int result = -ENODATA;
483 static char object_name[5] = {'_','Q','0','0','\0'}; 824 static char object_name[5] = {'_','Q','0','0','\0'};
@@ -497,9 +838,9 @@ acpi_ec_gpe_query (
497 838
498 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); 839 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name));
499 840
500 acpi_evaluate_object(ec->handle, object_name, NULL, NULL); 841 acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL);
501end: 842end:
502 atomic_dec(&ec->pending_gpe); 843 atomic_dec(&ec->burst.pending_gpe);
503 return; 844 return;
504} 845}
505 846
@@ -507,48 +848,77 @@ static u32
507acpi_ec_gpe_handler ( 848acpi_ec_gpe_handler (
508 void *data) 849 void *data)
509{ 850{
851 if (acpi_ec_polling_mode)
852 return acpi_ec_gpe_polling_handler(data);
853 else
854 return acpi_ec_gpe_burst_handler(data);
855}
856static u32
857acpi_ec_gpe_polling_handler (
858 void *data)
859{
860 acpi_status status = AE_OK;
861 union acpi_ec *ec = (union acpi_ec *) data;
862
863 if (!ec)
864 return ACPI_INTERRUPT_NOT_HANDLED;
865
866 acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR);
867
868 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
869 acpi_ec_gpe_query, ec);
870
871 if (status == AE_OK)
872 return ACPI_INTERRUPT_HANDLED;
873 else
874 return ACPI_INTERRUPT_NOT_HANDLED;
875}
876static u32
877acpi_ec_gpe_burst_handler (
878 void *data)
879{
510 acpi_status status = AE_OK; 880 acpi_status status = AE_OK;
511 u32 value; 881 u32 value;
512 struct acpi_ec *ec = (struct acpi_ec *) data; 882 union acpi_ec *ec = (union acpi_ec *) data;
513 883
514 if (!ec) 884 if (!ec)
515 return ACPI_INTERRUPT_NOT_HANDLED; 885 return ACPI_INTERRUPT_NOT_HANDLED;
516 886
517 acpi_disable_gpe(NULL, ec->gpe_bit, ACPI_ISR); 887 acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR);
518 888
519 value = acpi_ec_read_status(ec); 889 value = acpi_ec_read_status(ec);
520 890
521 if((value & ACPI_EC_FLAG_IBF) && 891 if((value & ACPI_EC_FLAG_IBF) &&
522 !(value & ACPI_EC_FLAG_BURST) && 892 !(value & ACPI_EC_FLAG_BURST) &&
523 (atomic_read(&ec->leaving_burst) == 0)) { 893 (atomic_read(&ec->burst.leaving_burst) == 0)) {
524 /* 894 /*
525 * the embedded controller disables 895 * the embedded controller disables
526 * burst mode for any reason other 896 * burst mode for any reason other
527 * than the burst disable command 897 * than the burst disable command
528 * to process critical event. 898 * to process critical event.
529 */ 899 */
530 atomic_set(&ec->leaving_burst , 2); /* block current pending transaction 900 atomic_set(&ec->burst.leaving_burst , 2); /* block current pending transaction
531 and retry */ 901 and retry */
532 wake_up(&ec->wait); 902 wake_up(&ec->burst.wait);
533 }else { 903 }else {
534 if ((ec->expect_event == ACPI_EC_EVENT_OBF && 904 if ((ec->burst.expect_event == ACPI_EC_EVENT_OBF &&
535 (value & ACPI_EC_FLAG_OBF)) || 905 (value & ACPI_EC_FLAG_OBF)) ||
536 (ec->expect_event == ACPI_EC_EVENT_IBE && 906 (ec->burst.expect_event == ACPI_EC_EVENT_IBE &&
537 !(value & ACPI_EC_FLAG_IBF))) { 907 !(value & ACPI_EC_FLAG_IBF))) {
538 ec->expect_event = 0; 908 ec->burst.expect_event = 0;
539 wake_up(&ec->wait); 909 wake_up(&ec->burst.wait);
540 return ACPI_INTERRUPT_HANDLED; 910 return ACPI_INTERRUPT_HANDLED;
541 } 911 }
542 } 912 }
543 913
544 if (value & ACPI_EC_FLAG_SCI){ 914 if (value & ACPI_EC_FLAG_SCI){
545 atomic_add(1, &ec->pending_gpe) ; 915 atomic_add(1, &ec->burst.pending_gpe) ;
546 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE, 916 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
547 acpi_ec_gpe_query, ec); 917 acpi_ec_gpe_query, ec);
548 return status == AE_OK ? 918 return status == AE_OK ?
549 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; 919 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
550 } 920 }
551 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_ISR); 921 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR);
552 return status == AE_OK ? 922 return status == AE_OK ?
553 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; 923 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
554} 924}
@@ -585,7 +955,7 @@ acpi_ec_space_handler (
585 void *region_context) 955 void *region_context)
586{ 956{
587 int result = 0; 957 int result = 0;
588 struct acpi_ec *ec = NULL; 958 union acpi_ec *ec = NULL;
589 u64 temp = *value; 959 u64 temp = *value;
590 acpi_integer f_v = 0; 960 acpi_integer f_v = 0;
591 int i = 0; 961 int i = 0;
@@ -600,7 +970,7 @@ acpi_ec_space_handler (
600 return_VALUE(AE_BAD_PARAMETER); 970 return_VALUE(AE_BAD_PARAMETER);
601 } 971 }
602 972
603 ec = (struct acpi_ec *) handler_context; 973 ec = (union acpi_ec *) handler_context;
604 974
605next_byte: 975next_byte:
606 switch (function) { 976 switch (function) {
@@ -661,7 +1031,7 @@ static struct proc_dir_entry *acpi_ec_dir;
661static int 1031static int
662acpi_ec_read_info (struct seq_file *seq, void *offset) 1032acpi_ec_read_info (struct seq_file *seq, void *offset)
663{ 1033{
664 struct acpi_ec *ec = (struct acpi_ec *) seq->private; 1034 union acpi_ec *ec = (union acpi_ec *) seq->private;
665 1035
666 ACPI_FUNCTION_TRACE("acpi_ec_read_info"); 1036 ACPI_FUNCTION_TRACE("acpi_ec_read_info");
667 1037
@@ -669,12 +1039,12 @@ acpi_ec_read_info (struct seq_file *seq, void *offset)
669 goto end; 1039 goto end;
670 1040
671 seq_printf(seq, "gpe bit: 0x%02x\n", 1041 seq_printf(seq, "gpe bit: 0x%02x\n",
672 (u32) ec->gpe_bit); 1042 (u32) ec->common.gpe_bit);
673 seq_printf(seq, "ports: 0x%02x, 0x%02x\n", 1043 seq_printf(seq, "ports: 0x%02x, 0x%02x\n",
674 (u32) ec->status_addr.address, (u32) ec->data_addr.address); 1044 (u32) ec->common.status_addr.address, (u32) ec->common.data_addr.address);
675 seq_printf(seq, "use global lock: %s\n", 1045 seq_printf(seq, "use global lock: %s\n",
676 ec->global_lock?"yes":"no"); 1046 ec->common.global_lock?"yes":"no");
677 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 1047 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
678 1048
679end: 1049end:
680 return_VALUE(0); 1050 return_VALUE(0);
@@ -697,7 +1067,7 @@ static int
697acpi_ec_add_fs ( 1067acpi_ec_add_fs (
698 struct acpi_device *device) 1068 struct acpi_device *device)
699{ 1069{
700 struct proc_dir_entry *entry; 1070 struct proc_dir_entry *entry = NULL;
701 1071
702 ACPI_FUNCTION_TRACE("acpi_ec_add_fs"); 1072 ACPI_FUNCTION_TRACE("acpi_ec_add_fs");
703 1073
@@ -744,13 +1114,82 @@ acpi_ec_remove_fs (
744 Driver Interface 1114 Driver Interface
745 -------------------------------------------------------------------------- */ 1115 -------------------------------------------------------------------------- */
746 1116
1117
747static int 1118static int
748acpi_ec_add ( 1119acpi_ec_polling_add (
749 struct acpi_device *device) 1120 struct acpi_device *device)
750{ 1121{
751 int result; 1122 int result = 0;
752 acpi_status status; 1123 acpi_status status = AE_OK;
753 struct acpi_ec *ec; 1124 union acpi_ec *ec = NULL;
1125 unsigned long uid;
1126
1127 ACPI_FUNCTION_TRACE("acpi_ec_add");
1128
1129 if (!device)
1130 return_VALUE(-EINVAL);
1131
1132 ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1133 if (!ec)
1134 return_VALUE(-ENOMEM);
1135 memset(ec, 0, sizeof(union acpi_ec));
1136
1137 ec->common.handle = device->handle;
1138 ec->common.uid = -1;
1139 spin_lock_init(&ec->polling.lock);
1140 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
1141 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
1142 acpi_driver_data(device) = ec;
1143
1144 /* Use the global lock for all EC transactions? */
1145 acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, &ec->common.global_lock);
1146
1147 /* If our UID matches the UID for the ECDT-enumerated EC,
1148 we now have the *real* EC info, so kill the makeshift one.*/
1149 acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid);
1150 if (ec_ecdt && ec_ecdt->common.uid == uid) {
1151 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
1152 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler);
1153
1154 acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, &acpi_ec_gpe_handler);
1155
1156 kfree(ec_ecdt);
1157 }
1158
1159 /* Get GPE bit assignment (EC events). */
1160 /* TODO: Add support for _GPE returning a package */
1161 status = acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, &ec->common.gpe_bit);
1162 if (ACPI_FAILURE(status)) {
1163 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1164 "Error obtaining GPE bit assignment\n"));
1165 result = -ENODEV;
1166 goto end;
1167 }
1168
1169 result = acpi_ec_add_fs(device);
1170 if (result)
1171 goto end;
1172
1173 printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n",
1174 acpi_device_name(device), acpi_device_bid(device),
1175 (u32) ec->common.gpe_bit);
1176
1177 if (!first_ec)
1178 first_ec = device;
1179
1180end:
1181 if (result)
1182 kfree(ec);
1183
1184 return_VALUE(result);
1185}
1186static int
1187acpi_ec_burst_add (
1188 struct acpi_device *device)
1189{
1190 int result = 0;
1191 acpi_status status = AE_OK;
1192 union acpi_ec *ec = NULL;
754 unsigned long uid; 1193 unsigned long uid;
755 1194
756 ACPI_FUNCTION_TRACE("acpi_ec_add"); 1195 ACPI_FUNCTION_TRACE("acpi_ec_add");
@@ -758,39 +1197,39 @@ acpi_ec_add (
758 if (!device) 1197 if (!device)
759 return_VALUE(-EINVAL); 1198 return_VALUE(-EINVAL);
760 1199
761 ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); 1200 ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
762 if (!ec) 1201 if (!ec)
763 return_VALUE(-ENOMEM); 1202 return_VALUE(-ENOMEM);
764 memset(ec, 0, sizeof(struct acpi_ec)); 1203 memset(ec, 0, sizeof(union acpi_ec));
765 1204
766 ec->handle = device->handle; 1205 ec->common.handle = device->handle;
767 ec->uid = -1; 1206 ec->common.uid = -1;
768 atomic_set(&ec->pending_gpe, 0); 1207 atomic_set(&ec->burst.pending_gpe, 0);
769 atomic_set(&ec->leaving_burst , 1); 1208 atomic_set(&ec->burst.leaving_burst , 1);
770 init_MUTEX(&ec->sem); 1209 init_MUTEX(&ec->burst.sem);
771 init_waitqueue_head(&ec->wait); 1210 init_waitqueue_head(&ec->burst.wait);
772 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); 1211 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
773 strcpy(acpi_device_class(device), ACPI_EC_CLASS); 1212 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
774 acpi_driver_data(device) = ec; 1213 acpi_driver_data(device) = ec;
775 1214
776 /* Use the global lock for all EC transactions? */ 1215 /* Use the global lock for all EC transactions? */
777 acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock); 1216 acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, &ec->common.global_lock);
778 1217
779 /* If our UID matches the UID for the ECDT-enumerated EC, 1218 /* If our UID matches the UID for the ECDT-enumerated EC,
780 we now have the *real* EC info, so kill the makeshift one.*/ 1219 we now have the *real* EC info, so kill the makeshift one.*/
781 acpi_evaluate_integer(ec->handle, "_UID", NULL, &uid); 1220 acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid);
782 if (ec_ecdt && ec_ecdt->uid == uid) { 1221 if (ec_ecdt && ec_ecdt->common.uid == uid) {
783 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, 1222 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
784 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); 1223 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler);
785 1224
786 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, &acpi_ec_gpe_handler); 1225 acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, &acpi_ec_gpe_handler);
787 1226
788 kfree(ec_ecdt); 1227 kfree(ec_ecdt);
789 } 1228 }
790 1229
791 /* Get GPE bit assignment (EC events). */ 1230 /* Get GPE bit assignment (EC events). */
792 /* TODO: Add support for _GPE returning a package */ 1231 /* TODO: Add support for _GPE returning a package */
793 status = acpi_evaluate_integer(ec->handle, "_GPE", NULL, &ec->gpe_bit); 1232 status = acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, &ec->common.gpe_bit);
794 if (ACPI_FAILURE(status)) { 1233 if (ACPI_FAILURE(status)) {
795 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1234 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
796 "Error obtaining GPE bit assignment\n")); 1235 "Error obtaining GPE bit assignment\n"));
@@ -804,7 +1243,7 @@ acpi_ec_add (
804 1243
805 printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n", 1244 printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n",
806 acpi_device_name(device), acpi_device_bid(device), 1245 acpi_device_name(device), acpi_device_bid(device),
807 (u32) ec->gpe_bit); 1246 (u32) ec->common.gpe_bit);
808 1247
809 if (!first_ec) 1248 if (!first_ec)
810 first_ec = device; 1249 first_ec = device;
@@ -822,7 +1261,7 @@ acpi_ec_remove (
822 struct acpi_device *device, 1261 struct acpi_device *device,
823 int type) 1262 int type)
824{ 1263{
825 struct acpi_ec *ec; 1264 union acpi_ec *ec = NULL;
826 1265
827 ACPI_FUNCTION_TRACE("acpi_ec_remove"); 1266 ACPI_FUNCTION_TRACE("acpi_ec_remove");
828 1267
@@ -844,7 +1283,7 @@ acpi_ec_io_ports (
844 struct acpi_resource *resource, 1283 struct acpi_resource *resource,
845 void *context) 1284 void *context)
846{ 1285{
847 struct acpi_ec *ec = (struct acpi_ec *) context; 1286 union acpi_ec *ec = (union acpi_ec *) context;
848 struct acpi_generic_address *addr; 1287 struct acpi_generic_address *addr;
849 1288
850 if (resource->id != ACPI_RSTYPE_IO) { 1289 if (resource->id != ACPI_RSTYPE_IO) {
@@ -856,10 +1295,10 @@ acpi_ec_io_ports (
856 * the second address region returned is the status/command 1295 * the second address region returned is the status/command
857 * port. 1296 * port.
858 */ 1297 */
859 if (ec->data_addr.register_bit_width == 0) { 1298 if (ec->common.data_addr.register_bit_width == 0) {
860 addr = &ec->data_addr; 1299 addr = &ec->common.data_addr;
861 } else if (ec->command_addr.register_bit_width == 0) { 1300 } else if (ec->common.command_addr.register_bit_width == 0) {
862 addr = &ec->command_addr; 1301 addr = &ec->common.command_addr;
863 } else { 1302 } else {
864 return AE_CTRL_TERMINATE; 1303 return AE_CTRL_TERMINATE;
865 } 1304 }
@@ -877,8 +1316,8 @@ static int
877acpi_ec_start ( 1316acpi_ec_start (
878 struct acpi_device *device) 1317 struct acpi_device *device)
879{ 1318{
880 acpi_status status; 1319 acpi_status status = AE_OK;
881 struct acpi_ec *ec; 1320 union acpi_ec *ec = NULL;
882 1321
883 ACPI_FUNCTION_TRACE("acpi_ec_start"); 1322 ACPI_FUNCTION_TRACE("acpi_ec_start");
884 1323
@@ -893,35 +1332,36 @@ acpi_ec_start (
893 /* 1332 /*
894 * Get I/O port addresses. Convert to GAS format. 1333 * Get I/O port addresses. Convert to GAS format.
895 */ 1334 */
896 status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS, 1335 status = acpi_walk_resources(ec->common.handle, METHOD_NAME__CRS,
897 acpi_ec_io_ports, ec); 1336 acpi_ec_io_ports, ec);
898 if (ACPI_FAILURE(status) || ec->command_addr.register_bit_width == 0) { 1337 if (ACPI_FAILURE(status) || ec->common.command_addr.register_bit_width == 0) {
899 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error getting I/O port addresses")); 1338 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error getting I/O port addresses"));
900 return_VALUE(-ENODEV); 1339 return_VALUE(-ENODEV);
901 } 1340 }
902 1341
903 ec->status_addr = ec->command_addr; 1342 ec->common.status_addr = ec->common.command_addr;
904 1343
905 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n", 1344 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n",
906 (u32) ec->gpe_bit, (u32) ec->command_addr.address, 1345 (u32) ec->common.gpe_bit, (u32) ec->common.command_addr.address,
907 (u32) ec->data_addr.address)); 1346 (u32) ec->common.data_addr.address));
1347
908 1348
909 /* 1349 /*
910 * Install GPE handler 1350 * Install GPE handler
911 */ 1351 */
912 status = acpi_install_gpe_handler(NULL, ec->gpe_bit, 1352 status = acpi_install_gpe_handler(NULL, ec->common.gpe_bit,
913 ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, ec); 1353 ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, ec);
914 if (ACPI_FAILURE(status)) { 1354 if (ACPI_FAILURE(status)) {
915 return_VALUE(-ENODEV); 1355 return_VALUE(-ENODEV);
916 } 1356 }
917 acpi_set_gpe_type (NULL, ec->gpe_bit, ACPI_GPE_TYPE_RUNTIME); 1357 acpi_set_gpe_type (NULL, ec->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME);
918 acpi_enable_gpe (NULL, ec->gpe_bit, ACPI_NOT_ISR); 1358 acpi_enable_gpe (NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
919 1359
920 status = acpi_install_address_space_handler (ec->handle, 1360 status = acpi_install_address_space_handler (ec->common.handle,
921 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, 1361 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler,
922 &acpi_ec_space_setup, ec); 1362 &acpi_ec_space_setup, ec);
923 if (ACPI_FAILURE(status)) { 1363 if (ACPI_FAILURE(status)) {
924 acpi_remove_gpe_handler(NULL, ec->gpe_bit, &acpi_ec_gpe_handler); 1364 acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, &acpi_ec_gpe_handler);
925 return_VALUE(-ENODEV); 1365 return_VALUE(-ENODEV);
926 } 1366 }
927 1367
@@ -934,8 +1374,8 @@ acpi_ec_stop (
934 struct acpi_device *device, 1374 struct acpi_device *device,
935 int type) 1375 int type)
936{ 1376{
937 acpi_status status; 1377 acpi_status status = AE_OK;
938 struct acpi_ec *ec; 1378 union acpi_ec *ec = NULL;
939 1379
940 ACPI_FUNCTION_TRACE("acpi_ec_stop"); 1380 ACPI_FUNCTION_TRACE("acpi_ec_stop");
941 1381
@@ -944,12 +1384,12 @@ acpi_ec_stop (
944 1384
945 ec = acpi_driver_data(device); 1385 ec = acpi_driver_data(device);
946 1386
947 status = acpi_remove_address_space_handler(ec->handle, 1387 status = acpi_remove_address_space_handler(ec->common.handle,
948 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); 1388 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler);
949 if (ACPI_FAILURE(status)) 1389 if (ACPI_FAILURE(status))
950 return_VALUE(-ENODEV); 1390 return_VALUE(-ENODEV);
951 1391
952 status = acpi_remove_gpe_handler(NULL, ec->gpe_bit, &acpi_ec_gpe_handler); 1392 status = acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, &acpi_ec_gpe_handler);
953 if (ACPI_FAILURE(status)) 1393 if (ACPI_FAILURE(status))
954 return_VALUE(-ENODEV); 1394 return_VALUE(-ENODEV);
955 1395
@@ -963,26 +1403,76 @@ acpi_fake_ecdt_callback (
963 void *context, 1403 void *context,
964 void **retval) 1404 void **retval)
965{ 1405{
1406
1407 if (acpi_ec_polling_mode)
1408 return acpi_fake_ecdt_polling_callback(handle,
1409 Level, context, retval);
1410 else
1411 return acpi_fake_ecdt_burst_callback(handle,
1412 Level, context, retval);
1413}
1414
1415static acpi_status __init
1416acpi_fake_ecdt_polling_callback (
1417 acpi_handle handle,
1418 u32 Level,
1419 void *context,
1420 void **retval)
1421{
1422 acpi_status status;
1423
1424 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
1425 acpi_ec_io_ports, ec_ecdt);
1426 if (ACPI_FAILURE(status))
1427 return status;
1428 ec_ecdt->common.status_addr = ec_ecdt->common.command_addr;
1429
1430 ec_ecdt->common.uid = -1;
1431 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid);
1432
1433 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->common.gpe_bit);
1434 if (ACPI_FAILURE(status))
1435 return status;
1436 spin_lock_init(&ec_ecdt->polling.lock);
1437 ec_ecdt->common.global_lock = TRUE;
1438 ec_ecdt->common.handle = handle;
1439
1440 printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n",
1441 (u32) ec_ecdt->common.gpe_bit, (u32) ec_ecdt->common.command_addr.address,
1442 (u32) ec_ecdt->common.data_addr.address);
1443
1444 return AE_CTRL_TERMINATE;
1445}
1446
1447static acpi_status __init
1448acpi_fake_ecdt_burst_callback (
1449 acpi_handle handle,
1450 u32 Level,
1451 void *context,
1452 void **retval)
1453{
966 acpi_status status; 1454 acpi_status status;
967 1455
1456 init_MUTEX(&ec_ecdt->burst.sem);
1457 init_waitqueue_head(&ec_ecdt->burst.wait);
968 status = acpi_walk_resources(handle, METHOD_NAME__CRS, 1458 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
969 acpi_ec_io_ports, ec_ecdt); 1459 acpi_ec_io_ports, ec_ecdt);
970 if (ACPI_FAILURE(status)) 1460 if (ACPI_FAILURE(status))
971 return status; 1461 return status;
972 ec_ecdt->status_addr = ec_ecdt->command_addr; 1462 ec_ecdt->common.status_addr = ec_ecdt->common.command_addr;
973 1463
974 ec_ecdt->uid = -1; 1464 ec_ecdt->common.uid = -1;
975 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid); 1465 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid);
976 1466
977 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe_bit); 1467 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->common.gpe_bit);
978 if (ACPI_FAILURE(status)) 1468 if (ACPI_FAILURE(status))
979 return status; 1469 return status;
980 ec_ecdt->global_lock = TRUE; 1470 ec_ecdt->common.global_lock = TRUE;
981 ec_ecdt->handle = handle; 1471 ec_ecdt->common.handle = handle;
982 1472
983 printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", 1473 printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n",
984 (u32) ec_ecdt->gpe_bit, (u32) ec_ecdt->command_addr.address, 1474 (u32) ec_ecdt->common.gpe_bit, (u32) ec_ecdt->common.command_addr.address,
985 (u32) ec_ecdt->data_addr.address); 1475 (u32) ec_ecdt->common.data_addr.address);
986 1476
987 return AE_CTRL_TERMINATE; 1477 return AE_CTRL_TERMINATE;
988} 1478}
@@ -1005,12 +1495,12 @@ acpi_ec_fake_ecdt(void)
1005 1495
1006 printk(KERN_INFO PREFIX "Try to make an fake ECDT\n"); 1496 printk(KERN_INFO PREFIX "Try to make an fake ECDT\n");
1007 1497
1008 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); 1498 ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1009 if (!ec_ecdt) { 1499 if (!ec_ecdt) {
1010 ret = -ENOMEM; 1500 ret = -ENOMEM;
1011 goto error; 1501 goto error;
1012 } 1502 }
1013 memset(ec_ecdt, 0, sizeof(struct acpi_ec)); 1503 memset(ec_ecdt, 0, sizeof(union acpi_ec));
1014 1504
1015 status = acpi_get_devices (ACPI_EC_HID, 1505 status = acpi_get_devices (ACPI_EC_HID,
1016 acpi_fake_ecdt_callback, 1506 acpi_fake_ecdt_callback,
@@ -1031,6 +1521,60 @@ error:
1031static int __init 1521static int __init
1032acpi_ec_get_real_ecdt(void) 1522acpi_ec_get_real_ecdt(void)
1033{ 1523{
1524 if (acpi_ec_polling_mode)
1525 return acpi_ec_polling_get_real_ecdt();
1526 else
1527 return acpi_ec_burst_get_real_ecdt();
1528}
1529
1530static int __init
1531acpi_ec_polling_get_real_ecdt(void)
1532{
1533 acpi_status status;
1534 struct acpi_table_ecdt *ecdt_ptr;
1535
1536 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
1537 (struct acpi_table_header **) &ecdt_ptr);
1538 if (ACPI_FAILURE(status))
1539 return -ENODEV;
1540
1541 printk(KERN_INFO PREFIX "Found ECDT\n");
1542
1543 /*
1544 * Generate a temporary ec context to use until the namespace is scanned
1545 */
1546 ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1547 if (!ec_ecdt)
1548 return -ENOMEM;
1549 memset(ec_ecdt, 0, sizeof(union acpi_ec));
1550
1551 ec_ecdt->common.command_addr = ecdt_ptr->ec_control;
1552 ec_ecdt->common.status_addr = ecdt_ptr->ec_control;
1553 ec_ecdt->common.data_addr = ecdt_ptr->ec_data;
1554 ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit;
1555 spin_lock_init(&ec_ecdt->polling.lock);
1556 /* use the GL just to be safe */
1557 ec_ecdt->common.global_lock = TRUE;
1558 ec_ecdt->common.uid = ecdt_ptr->uid;
1559
1560 status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle);
1561 if (ACPI_FAILURE(status)) {
1562 goto error;
1563 }
1564
1565 return 0;
1566error:
1567 printk(KERN_ERR PREFIX "Could not use ECDT\n");
1568 kfree(ec_ecdt);
1569 ec_ecdt = NULL;
1570
1571 return -ENODEV;
1572}
1573
1574
1575static int __init
1576acpi_ec_burst_get_real_ecdt(void)
1577{
1034 acpi_status status; 1578 acpi_status status;
1035 struct acpi_table_ecdt *ecdt_ptr; 1579 struct acpi_table_ecdt *ecdt_ptr;
1036 1580
@@ -1044,22 +1588,22 @@ acpi_ec_get_real_ecdt(void)
1044 /* 1588 /*
1045 * Generate a temporary ec context to use until the namespace is scanned 1589 * Generate a temporary ec context to use until the namespace is scanned
1046 */ 1590 */
1047 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); 1591 ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1048 if (!ec_ecdt) 1592 if (!ec_ecdt)
1049 return -ENOMEM; 1593 return -ENOMEM;
1050 memset(ec_ecdt, 0, sizeof(struct acpi_ec)); 1594 memset(ec_ecdt, 0, sizeof(union acpi_ec));
1051 1595
1052 init_MUTEX(&ec_ecdt->sem); 1596 init_MUTEX(&ec_ecdt->burst.sem);
1053 init_waitqueue_head(&ec_ecdt->wait); 1597 init_waitqueue_head(&ec_ecdt->burst.wait);
1054 ec_ecdt->command_addr = ecdt_ptr->ec_control; 1598 ec_ecdt->common.command_addr = ecdt_ptr->ec_control;
1055 ec_ecdt->status_addr = ecdt_ptr->ec_control; 1599 ec_ecdt->common.status_addr = ecdt_ptr->ec_control;
1056 ec_ecdt->data_addr = ecdt_ptr->ec_data; 1600 ec_ecdt->common.data_addr = ecdt_ptr->ec_data;
1057 ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit; 1601 ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit;
1058 /* use the GL just to be safe */ 1602 /* use the GL just to be safe */
1059 ec_ecdt->global_lock = TRUE; 1603 ec_ecdt->common.global_lock = TRUE;
1060 ec_ecdt->uid = ecdt_ptr->uid; 1604 ec_ecdt->common.uid = ecdt_ptr->uid;
1061 1605
1062 status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle); 1606 status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle);
1063 if (ACPI_FAILURE(status)) { 1607 if (ACPI_FAILURE(status)) {
1064 goto error; 1608 goto error;
1065 } 1609 }
@@ -1092,20 +1636,20 @@ acpi_ec_ecdt_probe (void)
1092 /* 1636 /*
1093 * Install GPE handler 1637 * Install GPE handler
1094 */ 1638 */
1095 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit, 1639 status = acpi_install_gpe_handler(NULL, ec_ecdt->common.gpe_bit,
1096 ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, 1640 ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler,
1097 ec_ecdt); 1641 ec_ecdt);
1098 if (ACPI_FAILURE(status)) { 1642 if (ACPI_FAILURE(status)) {
1099 goto error; 1643 goto error;
1100 } 1644 }
1101 acpi_set_gpe_type (NULL, ec_ecdt->gpe_bit, ACPI_GPE_TYPE_RUNTIME); 1645 acpi_set_gpe_type (NULL, ec_ecdt->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME);
1102 acpi_enable_gpe (NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR); 1646 acpi_enable_gpe (NULL, ec_ecdt->common.gpe_bit, ACPI_NOT_ISR);
1103 1647
1104 status = acpi_install_address_space_handler (ACPI_ROOT_OBJECT, 1648 status = acpi_install_address_space_handler (ACPI_ROOT_OBJECT,
1105 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, 1649 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler,
1106 &acpi_ec_space_setup, ec_ecdt); 1650 &acpi_ec_space_setup, ec_ecdt);
1107 if (ACPI_FAILURE(status)) { 1651 if (ACPI_FAILURE(status)) {
1108 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, 1652 acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit,
1109 &acpi_ec_gpe_handler); 1653 &acpi_ec_gpe_handler);
1110 goto error; 1654 goto error;
1111 } 1655 }
@@ -1123,7 +1667,7 @@ error:
1123 1667
1124static int __init acpi_ec_init (void) 1668static int __init acpi_ec_init (void)
1125{ 1669{
1126 int result; 1670 int result = 0;
1127 1671
1128 ACPI_FUNCTION_TRACE("acpi_ec_init"); 1672 ACPI_FUNCTION_TRACE("acpi_ec_init");
1129 1673
@@ -1167,3 +1711,10 @@ static int __init acpi_fake_ecdt_setup(char *str)
1167 return 0; 1711 return 0;
1168} 1712}
1169__setup("acpi_fake_ecdt", acpi_fake_ecdt_setup); 1713__setup("acpi_fake_ecdt", acpi_fake_ecdt_setup);
1714static int __init acpi_ec_set_polling_mode(char *str)
1715{
1716 acpi_ec_polling_mode = EC_POLLING;
1717 acpi_ec_driver.ops.add = acpi_ec_polling_add;
1718 return 0;
1719}
1720__setup("ec_polling", acpi_ec_set_polling_mode);
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
index d1f42b972821..bb973d2109a1 100644
--- a/drivers/acpi/pci_irq.c
+++ b/drivers/acpi/pci_irq.c
@@ -269,7 +269,51 @@ acpi_pci_irq_del_prt (int segment, int bus)
269/* -------------------------------------------------------------------------- 269/* --------------------------------------------------------------------------
270 PCI Interrupt Routing Support 270 PCI Interrupt Routing Support
271 -------------------------------------------------------------------------- */ 271 -------------------------------------------------------------------------- */
272typedef int (*irq_lookup_func)(struct acpi_prt_entry *, int *, int *, char **);
272 273
274static int
275acpi_pci_allocate_irq(struct acpi_prt_entry *entry,
276 int *edge_level,
277 int *active_high_low,
278 char **link)
279{
280 int irq;
281
282 ACPI_FUNCTION_TRACE("acpi_pci_allocate_irq");
283
284 if (entry->link.handle) {
285 irq = acpi_pci_link_allocate_irq(entry->link.handle,
286 entry->link.index, edge_level, active_high_low, link);
287 if (irq < 0) {
288 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid IRQ link routing entry\n"));
289 return_VALUE(-1);
290 }
291 } else {
292 irq = entry->link.index;
293 *edge_level = ACPI_LEVEL_SENSITIVE;
294 *active_high_low = ACPI_ACTIVE_LOW;
295 }
296
297 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", irq));
298 return_VALUE(irq);
299}
300
301static int
302acpi_pci_free_irq(struct acpi_prt_entry *entry,
303 int *edge_level,
304 int *active_high_low,
305 char **link)
306{
307 int irq;
308
309 ACPI_FUNCTION_TRACE("acpi_pci_free_irq");
310 if (entry->link.handle) {
311 irq = acpi_pci_link_free_irq(entry->link.handle);
312 } else {
313 irq = entry->link.index;
314 }
315 return_VALUE(irq);
316}
273/* 317/*
274 * acpi_pci_irq_lookup 318 * acpi_pci_irq_lookup
275 * success: return IRQ >= 0 319 * success: return IRQ >= 0
@@ -282,12 +326,13 @@ acpi_pci_irq_lookup (
282 int pin, 326 int pin,
283 int *edge_level, 327 int *edge_level,
284 int *active_high_low, 328 int *active_high_low,
285 char **link) 329 char **link,
330 irq_lookup_func func)
286{ 331{
287 struct acpi_prt_entry *entry = NULL; 332 struct acpi_prt_entry *entry = NULL;
288 int segment = pci_domain_nr(bus); 333 int segment = pci_domain_nr(bus);
289 int bus_nr = bus->number; 334 int bus_nr = bus->number;
290 int irq; 335 int ret;
291 336
292 ACPI_FUNCTION_TRACE("acpi_pci_irq_lookup"); 337 ACPI_FUNCTION_TRACE("acpi_pci_irq_lookup");
293 338
@@ -301,22 +346,8 @@ acpi_pci_irq_lookup (
301 return_VALUE(-1); 346 return_VALUE(-1);
302 } 347 }
303 348
304 if (entry->link.handle) { 349 ret = func(entry, edge_level, active_high_low, link);
305 irq = acpi_pci_link_get_irq(entry->link.handle, 350 return_VALUE(ret);
306 entry->link.index, edge_level, active_high_low, link);
307 if (irq < 0) {
308 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid IRQ link routing entry\n"));
309 return_VALUE(-1);
310 }
311 } else {
312 irq = entry->link.index;
313 *edge_level = ACPI_LEVEL_SENSITIVE;
314 *active_high_low = ACPI_ACTIVE_LOW;
315 }
316
317 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", irq));
318
319 return_VALUE(irq);
320} 351}
321 352
322/* 353/*
@@ -330,7 +361,8 @@ acpi_pci_irq_derive (
330 int pin, 361 int pin,
331 int *edge_level, 362 int *edge_level,
332 int *active_high_low, 363 int *active_high_low,
333 char **link) 364 char **link,
365 irq_lookup_func func)
334{ 366{
335 struct pci_dev *bridge = dev; 367 struct pci_dev *bridge = dev;
336 int irq = -1; 368 int irq = -1;
@@ -363,7 +395,7 @@ acpi_pci_irq_derive (
363 } 395 }
364 396
365 irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn), 397 irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn),
366 pin, edge_level, active_high_low, link); 398 pin, edge_level, active_high_low, link, func);
367 } 399 }
368 400
369 if (irq < 0) { 401 if (irq < 0) {
@@ -415,7 +447,7 @@ acpi_pci_irq_enable (
415 * values override any BIOS-assigned IRQs set during boot. 447 * values override any BIOS-assigned IRQs set during boot.
416 */ 448 */
417 irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin, 449 irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
418 &edge_level, &active_high_low, &link); 450 &edge_level, &active_high_low, &link, acpi_pci_allocate_irq);
419 451
420 /* 452 /*
421 * If no PRT entry was found, we'll try to derive an IRQ from the 453 * If no PRT entry was found, we'll try to derive an IRQ from the
@@ -423,7 +455,7 @@ acpi_pci_irq_enable (
423 */ 455 */
424 if (irq < 0) 456 if (irq < 0)
425 irq = acpi_pci_irq_derive(dev, pin, &edge_level, 457 irq = acpi_pci_irq_derive(dev, pin, &edge_level,
426 &active_high_low, &link); 458 &active_high_low, &link, acpi_pci_allocate_irq);
427 459
428 /* 460 /*
429 * No IRQ known to the ACPI subsystem - maybe the BIOS / 461 * No IRQ known to the ACPI subsystem - maybe the BIOS /
@@ -462,7 +494,9 @@ acpi_pci_irq_enable (
462EXPORT_SYMBOL(acpi_pci_irq_enable); 494EXPORT_SYMBOL(acpi_pci_irq_enable);
463 495
464 496
465#ifdef CONFIG_ACPI_DEALLOCATE_IRQ 497/* FIXME: implement x86/x86_64 version */
498void __attribute__((weak)) acpi_unregister_gsi(u32 i) {}
499
466void 500void
467acpi_pci_irq_disable ( 501acpi_pci_irq_disable (
468 struct pci_dev *dev) 502 struct pci_dev *dev)
@@ -489,14 +523,14 @@ acpi_pci_irq_disable (
489 * First we check the PCI IRQ routing table (PRT) for an IRQ. 523 * First we check the PCI IRQ routing table (PRT) for an IRQ.
490 */ 524 */
491 gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin, 525 gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
492 &edge_level, &active_high_low, NULL); 526 &edge_level, &active_high_low, NULL, acpi_pci_free_irq);
493 /* 527 /*
494 * If no PRT entry was found, we'll try to derive an IRQ from the 528 * If no PRT entry was found, we'll try to derive an IRQ from the
495 * device's parent bridge. 529 * device's parent bridge.
496 */ 530 */
497 if (gsi < 0) 531 if (gsi < 0)
498 gsi = acpi_pci_irq_derive(dev, pin, 532 gsi = acpi_pci_irq_derive(dev, pin,
499 &edge_level, &active_high_low, NULL); 533 &edge_level, &active_high_low, NULL, acpi_pci_free_irq);
500 if (gsi < 0) 534 if (gsi < 0)
501 return_VOID; 535 return_VOID;
502 536
@@ -512,4 +546,3 @@ acpi_pci_irq_disable (
512 546
513 return_VOID; 547 return_VOID;
514} 548}
515#endif /* CONFIG_ACPI_DEALLOCATE_IRQ */
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 6ad0e77df9b3..6a29610edc11 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -68,6 +68,10 @@ static struct acpi_driver acpi_pci_link_driver = {
68 }, 68 },
69}; 69};
70 70
71/*
72 * If a link is initialized, we never change its active and initialized
73 * later even the link is disable. Instead, we just repick the active irq
74 */
71struct acpi_pci_link_irq { 75struct acpi_pci_link_irq {
72 u8 active; /* Current IRQ */ 76 u8 active; /* Current IRQ */
73 u8 edge_level; /* All IRQs */ 77 u8 edge_level; /* All IRQs */
@@ -76,8 +80,7 @@ struct acpi_pci_link_irq {
76 u8 possible_count; 80 u8 possible_count;
77 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE]; 81 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
78 u8 initialized:1; 82 u8 initialized:1;
79 u8 suspend_resume:1; 83 u8 reserved:7;
80 u8 reserved:6;
81}; 84};
82 85
83struct acpi_pci_link { 86struct acpi_pci_link {
@@ -85,12 +88,14 @@ struct acpi_pci_link {
85 struct acpi_device *device; 88 struct acpi_device *device;
86 acpi_handle handle; 89 acpi_handle handle;
87 struct acpi_pci_link_irq irq; 90 struct acpi_pci_link_irq irq;
91 int refcnt;
88}; 92};
89 93
90static struct { 94static struct {
91 int count; 95 int count;
92 struct list_head entries; 96 struct list_head entries;
93} acpi_link; 97} acpi_link;
98DECLARE_MUTEX(acpi_link_lock);
94 99
95 100
96/* -------------------------------------------------------------------------- 101/* --------------------------------------------------------------------------
@@ -532,12 +537,12 @@ static int acpi_pci_link_allocate(
532 537
533 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate"); 538 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate");
534 539
535 if (link->irq.suspend_resume) { 540 if (link->irq.initialized) {
536 acpi_pci_link_set(link, link->irq.active); 541 if (link->refcnt == 0)
537 link->irq.suspend_resume = 0; 542 /* This means the link is disabled but initialized */
538 } 543 acpi_pci_link_set(link, link->irq.active);
539 if (link->irq.initialized)
540 return_VALUE(0); 544 return_VALUE(0);
545 }
541 546
542 /* 547 /*
543 * search for active IRQ in list of possible IRQs. 548 * search for active IRQ in list of possible IRQs.
@@ -596,13 +601,13 @@ static int acpi_pci_link_allocate(
596} 601}
597 602
598/* 603/*
599 * acpi_pci_link_get_irq 604 * acpi_pci_link_allocate_irq
600 * success: return IRQ >= 0 605 * success: return IRQ >= 0
601 * failure: return -1 606 * failure: return -1
602 */ 607 */
603 608
604int 609int
605acpi_pci_link_get_irq ( 610acpi_pci_link_allocate_irq (
606 acpi_handle handle, 611 acpi_handle handle,
607 int index, 612 int index,
608 int *edge_level, 613 int *edge_level,
@@ -613,7 +618,7 @@ acpi_pci_link_get_irq (
613 struct acpi_device *device = NULL; 618 struct acpi_device *device = NULL;
614 struct acpi_pci_link *link = NULL; 619 struct acpi_pci_link *link = NULL;
615 620
616 ACPI_FUNCTION_TRACE("acpi_pci_link_get_irq"); 621 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate_irq");
617 622
618 result = acpi_bus_get_device(handle, &device); 623 result = acpi_bus_get_device(handle, &device);
619 if (result) { 624 if (result) {
@@ -633,21 +638,70 @@ acpi_pci_link_get_irq (
633 return_VALUE(-1); 638 return_VALUE(-1);
634 } 639 }
635 640
636 if (acpi_pci_link_allocate(link)) 641 down(&acpi_link_lock);
642 if (acpi_pci_link_allocate(link)) {
643 up(&acpi_link_lock);
637 return_VALUE(-1); 644 return_VALUE(-1);
645 }
638 646
639 if (!link->irq.active) { 647 if (!link->irq.active) {
648 up(&acpi_link_lock);
640 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Link active IRQ is 0!\n")); 649 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Link active IRQ is 0!\n"));
641 return_VALUE(-1); 650 return_VALUE(-1);
642 } 651 }
652 link->refcnt ++;
653 up(&acpi_link_lock);
643 654
644 if (edge_level) *edge_level = link->irq.edge_level; 655 if (edge_level) *edge_level = link->irq.edge_level;
645 if (active_high_low) *active_high_low = link->irq.active_high_low; 656 if (active_high_low) *active_high_low = link->irq.active_high_low;
646 if (name) *name = acpi_device_bid(link->device); 657 if (name) *name = acpi_device_bid(link->device);
658 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
659 "Link %s is referenced\n", acpi_device_bid(link->device)));
647 return_VALUE(link->irq.active); 660 return_VALUE(link->irq.active);
648} 661}
649 662
663/*
664 * We don't change link's irq information here. After it is reenabled, we
665 * continue use the info
666 */
667int
668acpi_pci_link_free_irq(acpi_handle handle)
669{
670 struct acpi_device *device = NULL;
671 struct acpi_pci_link *link = NULL;
672 acpi_status result;
673
674 ACPI_FUNCTION_TRACE("acpi_pci_link_free_irq");
675
676 result = acpi_bus_get_device(handle, &device);
677 if (result) {
678 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link device\n"));
679 return_VALUE(-1);
680 }
650 681
682 link = (struct acpi_pci_link *) acpi_driver_data(device);
683 if (!link) {
684 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n"));
685 return_VALUE(-1);
686 }
687
688 down(&acpi_link_lock);
689 if (!link->irq.initialized) {
690 up(&acpi_link_lock);
691 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Link isn't initialized\n"));
692 return_VALUE(-1);
693 }
694
695 link->refcnt --;
696 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
697 "Link %s is dereferenced\n", acpi_device_bid(link->device)));
698
699 if (link->refcnt == 0) {
700 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL);
701 }
702 up(&acpi_link_lock);
703 return_VALUE(link->irq.active);
704}
651/* -------------------------------------------------------------------------- 705/* --------------------------------------------------------------------------
652 Driver Interface 706 Driver Interface
653 -------------------------------------------------------------------------- */ 707 -------------------------------------------------------------------------- */
@@ -677,6 +731,7 @@ acpi_pci_link_add (
677 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS); 731 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
678 acpi_driver_data(device) = link; 732 acpi_driver_data(device) = link;
679 733
734 down(&acpi_link_lock);
680 result = acpi_pci_link_get_possible(link); 735 result = acpi_pci_link_get_possible(link);
681 if (result) 736 if (result)
682 goto end; 737 goto end;
@@ -712,6 +767,7 @@ acpi_pci_link_add (
712end: 767end:
713 /* disable all links -- to be activated on use */ 768 /* disable all links -- to be activated on use */
714 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL); 769 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL);
770 up(&acpi_link_lock);
715 771
716 if (result) 772 if (result)
717 kfree(link); 773 kfree(link);
@@ -726,19 +782,32 @@ irqrouter_suspend(
726{ 782{
727 struct list_head *node = NULL; 783 struct list_head *node = NULL;
728 struct acpi_pci_link *link = NULL; 784 struct acpi_pci_link *link = NULL;
785 int ret = 0;
729 786
730 ACPI_FUNCTION_TRACE("irqrouter_suspend"); 787 ACPI_FUNCTION_TRACE("irqrouter_suspend");
731 788
732 list_for_each(node, &acpi_link.entries) { 789 list_for_each(node, &acpi_link.entries) {
733 link = list_entry(node, struct acpi_pci_link, node); 790 link = list_entry(node, struct acpi_pci_link, node);
734 if (!link) { 791 if (!link) {
735 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n")); 792 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
793 "Invalid link context\n"));
736 continue; 794 continue;
737 } 795 }
738 if (link->irq.active && link->irq.initialized) 796 if (link->irq.initialized && link->refcnt != 0
739 link->irq.suspend_resume = 1; 797 /* We ignore legacy IDE device irq */
798 && link->irq.active != 14 && link->irq.active !=15) {
799 printk(KERN_WARNING PREFIX
800 "%d drivers with interrupt %d neglected to call"
801 " pci_disable_device at .suspend\n",
802 link->refcnt,
803 link->irq.active);
804 printk(KERN_WARNING PREFIX
805 "Fix the driver, or rmmod before suspend\n");
806 link->refcnt = 0;
807 ret = -EINVAL;
808 }
740 } 809 }
741 return_VALUE(0); 810 return_VALUE(ret);
742} 811}
743 812
744 813
@@ -756,8 +825,9 @@ acpi_pci_link_remove (
756 825
757 link = (struct acpi_pci_link *) acpi_driver_data(device); 826 link = (struct acpi_pci_link *) acpi_driver_data(device);
758 827
759 /* TBD: Acquire/release lock */ 828 down(&acpi_link_lock);
760 list_del(&link->node); 829 list_del(&link->node);
830 up(&acpi_link_lock);
761 831
762 kfree(link); 832 kfree(link);
763 833
@@ -849,6 +919,7 @@ int __init acpi_irq_balance_set(char *str)
849__setup("acpi_irq_balance", acpi_irq_balance_set); 919__setup("acpi_irq_balance", acpi_irq_balance_set);
850 920
851 921
922/* FIXME: we will remove this interface after all drivers call pci_disable_device */
852static struct sysdev_class irqrouter_sysdev_class = { 923static struct sysdev_class irqrouter_sysdev_class = {
853 set_kset_name("irqrouter"), 924 set_kset_name("irqrouter"),
854 .suspend = irqrouter_suspend, 925 .suspend = irqrouter_suspend,
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 893b074e3d1a..af271d994f15 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -81,30 +81,33 @@ module_param(bm_history, uint, 0644);
81 * 81 *
82 * To skip this limit, boot/load with a large max_cstate limit. 82 * To skip this limit, boot/load with a large max_cstate limit.
83 */ 83 */
84static int no_c2c3(struct dmi_system_id *id) 84static int set_max_cstate(struct dmi_system_id *id)
85{ 85{
86 if (max_cstate > ACPI_PROCESSOR_MAX_POWER) 86 if (max_cstate > ACPI_PROCESSOR_MAX_POWER)
87 return 0; 87 return 0;
88 88
89 printk(KERN_NOTICE PREFIX "%s detected - C2,C3 disabled." 89 printk(KERN_NOTICE PREFIX "%s detected - %s disabled."
90 " Override with \"processor.max_cstate=%d\"\n", id->ident, 90 " Override with \"processor.max_cstate=%d\"\n", id->ident,
91 ((int)id->driver_data == 1)? "C2,C3":"C3",
91 ACPI_PROCESSOR_MAX_POWER + 1); 92 ACPI_PROCESSOR_MAX_POWER + 1);
92 93
93 max_cstate = 1; 94 max_cstate = (int)id->driver_data;
94 95
95 return 0; 96 return 0;
96} 97}
97 98
98 99
99
100
101static struct dmi_system_id __initdata processor_power_dmi_table[] = { 100static struct dmi_system_id __initdata processor_power_dmi_table[] = {
102 { no_c2c3, "IBM ThinkPad R40e", { 101 { set_max_cstate, "IBM ThinkPad R40e", {
103 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), 102 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
104 DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW") }}, 103 DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW") }, (void*)1},
105 { no_c2c3, "Medion 41700", { 104 { set_max_cstate, "Medion 41700", {
105 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
106 DMI_MATCH(DMI_BIOS_VERSION,"R01-A1J") }, (void*)1},
107 { set_max_cstate, "Clevo 5600D", {
106 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"), 108 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
107 DMI_MATCH(DMI_BIOS_VERSION,"R01-A1J") }}, 109 DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307") },
110 (void*)2},
108 {}, 111 {},
109}; 112};
110 113
@@ -549,7 +552,8 @@ static int acpi_processor_get_power_info_default_c1 (struct acpi_processor *pr)
549 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_default_c1"); 552 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_default_c1");
550 553
551 for (i = 0; i < ACPI_PROCESSOR_MAX_POWER; i++) 554 for (i = 0; i < ACPI_PROCESSOR_MAX_POWER; i++)
552 memset(pr->power.states, 0, sizeof(struct acpi_processor_cx)); 555 memset(&(pr->power.states[i]), 0,
556 sizeof(struct acpi_processor_cx));
553 557
554 /* if info is obtained from pblk/fadt, type equals state */ 558 /* if info is obtained from pblk/fadt, type equals state */
555 pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1; 559 pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1;
@@ -580,7 +584,8 @@ static int acpi_processor_get_power_info_cst (struct acpi_processor *pr)
580 584
581 pr->power.count = 0; 585 pr->power.count = 0;
582 for (i = 0; i < ACPI_PROCESSOR_MAX_POWER; i++) 586 for (i = 0; i < ACPI_PROCESSOR_MAX_POWER; i++)
583 memset(pr->power.states, 0, sizeof(struct acpi_processor_cx)); 587 memset(&(pr->power.states[i]), 0,
588 sizeof(struct acpi_processor_cx));
584 589
585 status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer); 590 status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer);
586 if (ACPI_FAILURE(status)) { 591 if (ACPI_FAILURE(status)) {
@@ -763,7 +768,6 @@ static void acpi_processor_power_verify_c3(
763 } 768 }
764 769
765 if (pr->flags.bm_check) { 770 if (pr->flags.bm_check) {
766 printk("Disabling BM access before entering C3\n");
767 /* bus mastering control is necessary */ 771 /* bus mastering control is necessary */
768 if (!pr->flags.bm_control) { 772 if (!pr->flags.bm_control) {
769 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 773 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -771,7 +775,6 @@ static void acpi_processor_power_verify_c3(
771 return_VOID; 775 return_VOID;
772 } 776 }
773 } else { 777 } else {
774 printk("Invalidating cache before entering C3\n");
775 /* 778 /*
776 * WBINVD should be set in fadt, for C3 state to be 779 * WBINVD should be set in fadt, for C3 state to be
777 * supported on when bm_check is not required. 780 * supported on when bm_check is not required.
@@ -842,7 +845,7 @@ static int acpi_processor_get_power_info (
842 result = acpi_processor_get_power_info_cst(pr); 845 result = acpi_processor_get_power_info_cst(pr);
843 if ((result) || (acpi_processor_power_verify(pr) < 2)) { 846 if ((result) || (acpi_processor_power_verify(pr) < 2)) {
844 result = acpi_processor_get_power_info_fadt(pr); 847 result = acpi_processor_get_power_info_fadt(pr);
845 if (result) 848 if ((result) || (acpi_processor_power_verify(pr) < 2))
846 result = acpi_processor_get_power_info_default_c1(pr); 849 result = acpi_processor_get_power_info_default_c1(pr);
847 } 850 }
848 851
diff --git a/drivers/net/sk98lin/skge.c b/drivers/net/sk98lin/skge.c
index 82570ec44d8e..074521a36341 100644
--- a/drivers/net/sk98lin/skge.c
+++ b/drivers/net/sk98lin/skge.c
@@ -5133,6 +5133,67 @@ static void __devexit skge_remove_one(struct pci_dev *pdev)
5133 kfree(pAC); 5133 kfree(pAC);
5134} 5134}
5135 5135
5136#ifdef CONFIG_PM
5137static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
5138{
5139 struct net_device *dev = pci_get_drvdata(pdev);
5140 DEV_NET *pNet = netdev_priv(dev);
5141 SK_AC *pAC = pNet->pAC;
5142 struct net_device *otherdev = pAC->dev[1];
5143
5144 if (pNet->Up) {
5145 pAC->WasIfUp[0] = SK_TRUE;
5146 DoPrintInterfaceChange = SK_FALSE;
5147 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
5148 }
5149 if (otherdev != dev) {
5150 pNet = netdev_priv(otherdev);
5151 if (pNet->Up) {
5152 pAC->WasIfUp[1] = SK_TRUE;
5153 DoPrintInterfaceChange = SK_FALSE;
5154 SkDrvDeInitAdapter(pAC, 1); /* performs SkGeClose */
5155 }
5156 }
5157
5158 pci_save_state(pdev);
5159 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
5160 if (pAC->AllocFlag & SK_ALLOC_IRQ) {
5161 free_irq(dev->irq, dev);
5162 }
5163 pci_disable_device(pdev);
5164 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5165
5166 return 0;
5167}
5168
5169static int skge_resume(struct pci_dev *pdev)
5170{
5171 struct net_device *dev = pci_get_drvdata(pdev);
5172 DEV_NET *pNet = netdev_priv(dev);
5173 SK_AC *pAC = pNet->pAC;
5174
5175 pci_set_power_state(pdev, PCI_D0);
5176 pci_restore_state(pdev);
5177 pci_enable_device(pdev);
5178 pci_set_master(pdev);
5179 if (pAC->GIni.GIMacsFound == 2)
5180 request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
5181 else
5182 request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ, pAC->Name, dev);
5183
5184 if (pAC->WasIfUp[0] == SK_TRUE) {
5185 DoPrintInterfaceChange = SK_FALSE;
5186 SkDrvInitAdapter(pAC, 0); /* first device */
5187 }
5188 if (pAC->dev[1] != dev && pAC->WasIfUp[1] == SK_TRUE) {
5189 DoPrintInterfaceChange = SK_FALSE;
5190 SkDrvInitAdapter(pAC, 1); /* first device */
5191 }
5192
5193 return 0;
5194}
5195#endif
5196
5136static struct pci_device_id skge_pci_tbl[] = { 5197static struct pci_device_id skge_pci_tbl[] = {
5137 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 5198 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5138 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 5199 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
@@ -5158,6 +5219,8 @@ static struct pci_driver skge_driver = {
5158 .id_table = skge_pci_tbl, 5219 .id_table = skge_pci_tbl,
5159 .probe = skge_probe_one, 5220 .probe = skge_probe_one,
5160 .remove = __devexit_p(skge_remove_one), 5221 .remove = __devexit_p(skge_remove_one),
5222 .suspend = skge_suspend,
5223 .resume = skge_resume,
5161}; 5224};
5162 5225
5163static int __init skge_init(void) 5226static int __init skge_init(void)
diff --git a/include/acpi/acpi_drivers.h b/include/acpi/acpi_drivers.h
index caeaa71a5663..579fe191b7e7 100644
--- a/include/acpi/acpi_drivers.h
+++ b/include/acpi/acpi_drivers.h
@@ -56,8 +56,9 @@
56/* ACPI PCI Interrupt Link (pci_link.c) */ 56/* ACPI PCI Interrupt Link (pci_link.c) */
57 57
58int acpi_irq_penalty_init (void); 58int acpi_irq_penalty_init (void);
59int acpi_pci_link_get_irq (acpi_handle handle, int index, int *edge_level, 59int acpi_pci_link_allocate_irq (acpi_handle handle, int index, int *edge_level,
60 int *active_high_low, char **name); 60 int *active_high_low, char **name);
61int acpi_pci_link_free_irq(acpi_handle handle);
61 62
62/* ACPI PCI Interrupt Routing (pci_irq.c) */ 63/* ACPI PCI Interrupt Routing (pci_irq.c) */
63 64
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index f85cbe919e13..b46a5205ee7b 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -453,9 +453,7 @@ int acpi_gsi_to_irq (u32 gsi, unsigned int *irq);
453 * If this matches the last registration, any IRQ resources for gsi 453 * If this matches the last registration, any IRQ resources for gsi
454 * are freed. 454 * are freed.
455 */ 455 */
456#ifdef CONFIG_ACPI_DEALLOCATE_IRQ
457void acpi_unregister_gsi (u32 gsi); 456void acpi_unregister_gsi (u32 gsi);
458#endif
459 457
460#ifdef CONFIG_ACPI_PCI 458#ifdef CONFIG_ACPI_PCI
461 459
@@ -480,9 +478,7 @@ struct pci_dev;
480int acpi_pci_irq_enable (struct pci_dev *dev); 478int acpi_pci_irq_enable (struct pci_dev *dev);
481void acpi_penalize_isa_irq(int irq, int active); 479void acpi_penalize_isa_irq(int irq, int active);
482 480
483#ifdef CONFIG_ACPI_DEALLOCATE_IRQ
484void acpi_pci_irq_disable (struct pci_dev *dev); 481void acpi_pci_irq_disable (struct pci_dev *dev);
485#endif
486 482
487struct acpi_pci_driver { 483struct acpi_pci_driver {
488 struct acpi_pci_driver *next; 484 struct acpi_pci_driver *next;
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 7c806bd9cc90..d7af3e474432 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -2376,6 +2376,9 @@ static int intel8x0_suspend(snd_card_t *card, pm_message_t state)
2376 snd_ac97_suspend(chip->ac97[i]); 2376 snd_ac97_suspend(chip->ac97[i]);
2377 if (chip->device_type == DEVICE_INTEL_ICH4) 2377 if (chip->device_type == DEVICE_INTEL_ICH4)
2378 chip->sdm_saved = igetbyte(chip, ICHREG(SDM)); 2378 chip->sdm_saved = igetbyte(chip, ICHREG(SDM));
2379
2380 if (chip->irq >= 0)
2381 free_irq(chip->irq, (void *)chip);
2379 pci_disable_device(chip->pci); 2382 pci_disable_device(chip->pci);
2380 return 0; 2383 return 0;
2381} 2384}
@@ -2387,7 +2390,9 @@ static int intel8x0_resume(snd_card_t *card)
2387 2390
2388 pci_enable_device(chip->pci); 2391 pci_enable_device(chip->pci);
2389 pci_set_master(chip->pci); 2392 pci_set_master(chip->pci);
2390 snd_intel8x0_chip_init(chip, 0); 2393 request_irq(chip->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip);
2394 synchronize_irq(chip->irq);
2395 snd_intel8x0_chip_init(chip, 1);
2391 2396
2392 /* re-initialize mixer stuff */ 2397 /* re-initialize mixer stuff */
2393 if (chip->device_type == DEVICE_INTEL_ICH4) { 2398 if (chip->device_type == DEVICE_INTEL_ICH4) {