blob: fe6768a7d658bfda2f671c663f4a4e60178e38c7 [file] [log] [blame]
Hannes Reineckee3a59b42007-02-07 18:19:37 +01001/*
2 * ide-acpi.c
3 * Provides ACPI support for IDE drives.
4 *
5 * Copyright (C) 2005 Intel Corp.
6 * Copyright (C) 2005 Randy Dunlap
7 * Copyright (C) 2006 SUSE Linux Products GmbH
8 * Copyright (C) 2006 Hannes Reinecke
9 */
10
11#include <linux/ata.h>
12#include <linux/delay.h>
13#include <linux/device.h>
14#include <linux/errno.h>
15#include <linux/kernel.h>
16#include <acpi/acpi.h>
17#include <linux/ide.h>
18#include <linux/pci.h>
Shaohua Li90494892008-01-10 23:03:42 +010019#include <linux/dmi.h>
Hannes Reineckee3a59b42007-02-07 18:19:37 +010020
21#include <acpi/acpi_bus.h>
22#include <acpi/acnames.h>
23#include <acpi/acnamesp.h>
24#include <acpi/acparser.h>
25#include <acpi/acexcep.h>
26#include <acpi/acmacros.h>
27#include <acpi/actypes.h>
28
29#define REGS_PER_GTF 7
30struct taskfile_array {
31 u8 tfa[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */
32};
33
34struct GTM_buffer {
35 u32 PIO_speed0;
36 u32 DMA_speed0;
37 u32 PIO_speed1;
38 u32 DMA_speed1;
39 u32 GTM_flags;
40};
41
42struct ide_acpi_drive_link {
43 ide_drive_t *drive;
44 acpi_handle obj_handle;
45 u8 idbuff[512];
46};
47
48struct ide_acpi_hwif_link {
49 ide_hwif_t *hwif;
50 acpi_handle obj_handle;
51 struct GTM_buffer gtm;
52 struct ide_acpi_drive_link master;
53 struct ide_acpi_drive_link slave;
54};
55
56#undef DEBUGGING
57/* note: adds function name and KERN_DEBUG */
58#ifdef DEBUGGING
59#define DEBPRINT(fmt, args...) \
60 printk(KERN_DEBUG "%s: " fmt, __FUNCTION__, ## args)
61#else
62#define DEBPRINT(fmt, args...) do {} while (0)
63#endif /* DEBUGGING */
64
65extern int ide_noacpi;
66extern int ide_noacpitfs;
67extern int ide_noacpionboot;
68
Shaohua Li90494892008-01-10 23:03:42 +010069static bool ide_noacpi_psx;
70static int no_acpi_psx(const struct dmi_system_id *id)
71{
72 ide_noacpi_psx = true;
73 printk(KERN_NOTICE"%s detected - disable ACPI _PSx.\n", id->ident);
74 return 0;
75}
76
77static const struct dmi_system_id ide_acpi_dmi_table[] = {
78 /* Bug 9673. */
79 /* We should check if this is because ACPI NVS isn't save/restored. */
80 {
81 .callback = no_acpi_psx,
82 .ident = "HP nx9005",
83 .matches = {
84 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies Ltd."),
85 DMI_MATCH(DMI_BIOS_VERSION, "KAM1.60")
86 },
87 },
88};
89
90static int ide_acpi_blacklist(void)
91{
92 static int done;
93 if (done)
94 return 0;
95 done = 1;
96 dmi_check_system(ide_acpi_dmi_table);
97 return 0;
98}
99
Hannes Reineckee3a59b42007-02-07 18:19:37 +0100100/**
101 * ide_get_dev_handle - finds acpi_handle and PCI device.function
102 * @dev: device to locate
103 * @handle: returned acpi_handle for @dev
104 * @pcidevfn: return PCI device.func for @dev
105 *
106 * Returns the ACPI object handle to the corresponding PCI device.
107 *
108 * Returns 0 on success, <0 on error.
109 */
110static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,
111 acpi_integer *pcidevfn)
112{
113 struct pci_dev *pdev = to_pci_dev(dev);
114 unsigned int bus, devnum, func;
115 acpi_integer addr;
116 acpi_handle dev_handle;
117 struct acpi_buffer buffer = {.length = ACPI_ALLOCATE_BUFFER,
118 .pointer = NULL};
119 acpi_status status;
120 struct acpi_device_info *dinfo = NULL;
121 int ret = -ENODEV;
122
123 bus = pdev->bus->number;
124 devnum = PCI_SLOT(pdev->devfn);
125 func = PCI_FUNC(pdev->devfn);
126 /* ACPI _ADR encoding for PCI bus: */
127 addr = (acpi_integer)(devnum << 16 | func);
128
129 DEBPRINT("ENTER: pci %02x:%02x.%01x\n", bus, devnum, func);
130
131 dev_handle = DEVICE_ACPI_HANDLE(dev);
132 if (!dev_handle) {
133 DEBPRINT("no acpi handle for device\n");
134 goto err;
135 }
136
137 status = acpi_get_object_info(dev_handle, &buffer);
138 if (ACPI_FAILURE(status)) {
139 DEBPRINT("get_object_info for device failed\n");
140 goto err;
141 }
142 dinfo = buffer.pointer;
143 if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
144 dinfo->address == addr) {
145 *pcidevfn = addr;
146 *handle = dev_handle;
147 } else {
148 DEBPRINT("get_object_info for device has wrong "
149 " address: %llu, should be %u\n",
150 dinfo ? (unsigned long long)dinfo->address : -1ULL,
151 (unsigned int)addr);
152 goto err;
153 }
154
155 DEBPRINT("for dev=0x%x.%x, addr=0x%llx, *handle=0x%p\n",
156 devnum, func, (unsigned long long)addr, *handle);
157 ret = 0;
158err:
159 kfree(dinfo);
160 return ret;
161}
162
163/**
164 * ide_acpi_hwif_get_handle - Get ACPI object handle for a given hwif
165 * @hwif: device to locate
166 *
167 * Retrieves the object handle for a given hwif.
168 *
169 * Returns handle on success, 0 on error.
170 */
171static acpi_handle ide_acpi_hwif_get_handle(ide_hwif_t *hwif)
172{
173 struct device *dev = hwif->gendev.parent;
174 acpi_handle dev_handle;
175 acpi_integer pcidevfn;
176 acpi_handle chan_handle;
177 int err;
178
179 DEBPRINT("ENTER: device %s\n", hwif->name);
180
181 if (!dev) {
182 DEBPRINT("no PCI device for %s\n", hwif->name);
183 return NULL;
184 }
185
186 err = ide_get_dev_handle(dev, &dev_handle, &pcidevfn);
187 if (err < 0) {
188 DEBPRINT("ide_get_dev_handle failed (%d)\n", err);
189 return NULL;
190 }
191
192 /* get child objects of dev_handle == channel objects,
193 * + _their_ children == drive objects */
194 /* channel is hwif->channel */
195 chan_handle = acpi_get_child(dev_handle, hwif->channel);
196 DEBPRINT("chan adr=%d: handle=0x%p\n",
197 hwif->channel, chan_handle);
198
199 return chan_handle;
200}
201
202/**
203 * ide_acpi_drive_get_handle - Get ACPI object handle for a given drive
204 * @drive: device to locate
205 *
206 * Retrieves the object handle of a given drive. According to the ACPI
207 * spec the drive is a child of the hwif.
208 *
209 * Returns handle on success, 0 on error.
210 */
211static acpi_handle ide_acpi_drive_get_handle(ide_drive_t *drive)
212{
213 ide_hwif_t *hwif = HWIF(drive);
214 int port;
215 acpi_handle drive_handle;
216
217 if (!hwif->acpidata)
218 return NULL;
219
220 if (!hwif->acpidata->obj_handle)
221 return NULL;
222
223 port = hwif->channel ? drive->dn - 2: drive->dn;
224
225 DEBPRINT("ENTER: %s at channel#: %d port#: %d\n",
226 drive->name, hwif->channel, port);
227
228
229 /* TBD: could also check ACPI object VALID bits */
230 drive_handle = acpi_get_child(hwif->acpidata->obj_handle, port);
231 DEBPRINT("drive %s handle 0x%p\n", drive->name, drive_handle);
232
233 return drive_handle;
234}
235
236/**
237 * do_drive_get_GTF - get the drive bootup default taskfile settings
238 * @drive: the drive for which the taskfile settings should be retrieved
239 * @gtf_length: number of bytes of _GTF data returned at @gtf_address
240 * @gtf_address: buffer containing _GTF taskfile arrays
241 *
242 * The _GTF method has no input parameters.
243 * It returns a variable number of register set values (registers
244 * hex 1F1..1F7, taskfiles).
245 * The <variable number> is not known in advance, so have ACPI-CA
246 * allocate the buffer as needed and return it, then free it later.
247 *
248 * The returned @gtf_length and @gtf_address are only valid if the
249 * function return value is 0.
250 */
251static int do_drive_get_GTF(ide_drive_t *drive,
252 unsigned int *gtf_length, unsigned long *gtf_address,
253 unsigned long *obj_loc)
254{
255 acpi_status status;
256 struct acpi_buffer output;
257 union acpi_object *out_obj;
258 ide_hwif_t *hwif = HWIF(drive);
259 struct device *dev = hwif->gendev.parent;
260 int err = -ENODEV;
261 int port;
262
263 *gtf_length = 0;
264 *gtf_address = 0UL;
265 *obj_loc = 0UL;
266
267 if (ide_noacpi)
268 return 0;
269
270 if (!dev) {
271 DEBPRINT("no PCI device for %s\n", hwif->name);
272 goto out;
273 }
274
275 if (!hwif->acpidata) {
276 DEBPRINT("no ACPI data for %s\n", hwif->name);
277 goto out;
278 }
279
280 port = hwif->channel ? drive->dn - 2: drive->dn;
281
282 if (!drive->acpidata) {
283 if (port == 0) {
284 drive->acpidata = &hwif->acpidata->master;
285 hwif->acpidata->master.drive = drive;
286 } else {
287 drive->acpidata = &hwif->acpidata->slave;
288 hwif->acpidata->slave.drive = drive;
289 }
290 }
291
292 DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
293 hwif->name, dev->bus_id, port, hwif->channel);
294
295 if (!drive->present) {
296 DEBPRINT("%s drive %d:%d not present\n",
297 hwif->name, hwif->channel, port);
298 goto out;
299 }
300
301 /* Get this drive's _ADR info. if not already known. */
302 if (!drive->acpidata->obj_handle) {
303 drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
304 if (!drive->acpidata->obj_handle) {
305 DEBPRINT("No ACPI object found for %s\n",
306 drive->name);
307 goto out;
308 }
309 }
310
311 /* Setting up output buffer */
312 output.length = ACPI_ALLOCATE_BUFFER;
313 output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
314
315 /* _GTF has no input parameters */
316 err = -EIO;
317 status = acpi_evaluate_object(drive->acpidata->obj_handle, "_GTF",
318 NULL, &output);
319 if (ACPI_FAILURE(status)) {
320 printk(KERN_DEBUG
321 "%s: Run _GTF error: status = 0x%x\n",
322 __FUNCTION__, status);
323 goto out;
324 }
325
326 if (!output.length || !output.pointer) {
327 DEBPRINT("Run _GTF: "
328 "length or ptr is NULL (0x%llx, 0x%p)\n",
329 (unsigned long long)output.length,
330 output.pointer);
331 goto out;
332 }
333
334 out_obj = output.pointer;
335 if (out_obj->type != ACPI_TYPE_BUFFER) {
336 DEBPRINT("Run _GTF: error: "
337 "expected object type of ACPI_TYPE_BUFFER, "
338 "got 0x%x\n", out_obj->type);
339 err = -ENOENT;
340 kfree(output.pointer);
341 goto out;
342 }
343
344 if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
345 out_obj->buffer.length % REGS_PER_GTF) {
346 printk(KERN_ERR
347 "%s: unexpected GTF length (%d) or addr (0x%p)\n",
348 __FUNCTION__, out_obj->buffer.length,
349 out_obj->buffer.pointer);
350 err = -ENOENT;
351 kfree(output.pointer);
352 goto out;
353 }
354
355 *gtf_length = out_obj->buffer.length;
356 *gtf_address = (unsigned long)out_obj->buffer.pointer;
357 *obj_loc = (unsigned long)out_obj;
358 DEBPRINT("returning gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
359 *gtf_length, *gtf_address, *obj_loc);
360 err = 0;
361out:
362 return err;
363}
364
365/**
366 * taskfile_load_raw - send taskfile registers to drive
367 * @drive: drive to which output is sent
368 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
369 *
370 * Outputs IDE taskfile to the drive.
371 */
372static int taskfile_load_raw(ide_drive_t *drive,
373 const struct taskfile_array *gtf)
374{
375 ide_task_t args;
376 int err = 0;
377
378 DEBPRINT("(0x1f1-1f7): hex: "
379 "%02x %02x %02x %02x %02x %02x %02x\n",
380 gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
381 gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
382
383 memset(&args, 0, sizeof(ide_task_t));
384 args.command_type = IDE_DRIVE_TASK_NO_DATA;
Bartlomiej Zolnierkiewicz892470b2007-10-20 00:32:37 +0200385 args.data_phase = TASKFILE_NO_DATA;
Hannes Reineckee3a59b42007-02-07 18:19:37 +0100386 args.handler = &task_no_data_intr;
387
388 /* convert gtf to IDE Taskfile */
389 args.tfRegister[1] = gtf->tfa[0]; /* 0x1f1 */
390 args.tfRegister[2] = gtf->tfa[1]; /* 0x1f2 */
391 args.tfRegister[3] = gtf->tfa[2]; /* 0x1f3 */
392 args.tfRegister[4] = gtf->tfa[3]; /* 0x1f4 */
393 args.tfRegister[5] = gtf->tfa[4]; /* 0x1f5 */
394 args.tfRegister[6] = gtf->tfa[5]; /* 0x1f6 */
395 args.tfRegister[7] = gtf->tfa[6]; /* 0x1f7 */
396
397 if (ide_noacpitfs) {
398 DEBPRINT("_GTF execution disabled\n");
399 return err;
400 }
401
402 err = ide_raw_taskfile(drive, &args, NULL);
403 if (err)
404 printk(KERN_ERR "%s: ide_raw_taskfile failed: %u\n",
405 __FUNCTION__, err);
406
407 return err;
408}
409
410/**
411 * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
412 * @drive: the drive to which the taskfile command should be sent
413 * @gtf_length: total number of bytes of _GTF taskfiles
414 * @gtf_address: location of _GTF taskfile arrays
415 *
416 * Write {gtf_address, length gtf_length} in groups of
417 * REGS_PER_GTF bytes.
418 */
419static int do_drive_set_taskfiles(ide_drive_t *drive,
420 unsigned int gtf_length,
421 unsigned long gtf_address)
422{
423 int rc = -ENODEV, err;
424 int gtf_count = gtf_length / REGS_PER_GTF;
425 int ix;
426 struct taskfile_array *gtf;
427
428 if (ide_noacpi)
429 return 0;
430
431 DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn);
432
433 if (!drive->present)
434 goto out;
435 if (!gtf_count) /* shouldn't be here */
436 goto out;
437
438 DEBPRINT("total GTF bytes=%u (0x%x), gtf_count=%d, addr=0x%lx\n",
439 gtf_length, gtf_length, gtf_count, gtf_address);
440
441 if (gtf_length % REGS_PER_GTF) {
442 printk(KERN_ERR "%s: unexpected GTF length (%d)\n",
443 __FUNCTION__, gtf_length);
444 goto out;
445 }
446
447 rc = 0;
448 for (ix = 0; ix < gtf_count; ix++) {
449 gtf = (struct taskfile_array *)
450 (gtf_address + ix * REGS_PER_GTF);
451
452 /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
453 err = taskfile_load_raw(drive, gtf);
454 if (err)
455 rc = err;
456 }
457
458out:
459 return rc;
460}
461
462/**
463 * ide_acpi_exec_tfs - get then write drive taskfile settings
464 * @drive: the drive for which the taskfile settings should be
465 * written.
466 *
467 * According to the ACPI spec this should be called after _STM
468 * has been evaluated for the interface. Some ACPI vendors interpret
469 * that as a hard requirement and modify the taskfile according
470 * to the Identify Drive information passed down with _STM.
471 * So one should really make sure to call this only after _STM has
472 * been executed.
473 */
474int ide_acpi_exec_tfs(ide_drive_t *drive)
475{
476 int ret;
477 unsigned int gtf_length;
478 unsigned long gtf_address;
479 unsigned long obj_loc;
480
481 if (ide_noacpi)
482 return 0;
483
484 DEBPRINT("call get_GTF, drive=%s port=%d\n", drive->name, drive->dn);
485
486 ret = do_drive_get_GTF(drive, &gtf_length, &gtf_address, &obj_loc);
487 if (ret < 0) {
488 DEBPRINT("get_GTF error (%d)\n", ret);
489 return ret;
490 }
491
492 DEBPRINT("call set_taskfiles, drive=%s\n", drive->name);
493
494 ret = do_drive_set_taskfiles(drive, gtf_length, gtf_address);
495 kfree((void *)obj_loc);
496 if (ret < 0) {
497 DEBPRINT("set_taskfiles error (%d)\n", ret);
498 }
499
500 DEBPRINT("ret=%d\n", ret);
501
502 return ret;
503}
504EXPORT_SYMBOL_GPL(ide_acpi_exec_tfs);
505
506/**
507 * ide_acpi_get_timing - get the channel (controller) timings
508 * @hwif: target IDE interface (channel)
509 *
510 * This function executes the _GTM ACPI method for the target channel.
511 *
512 */
513void ide_acpi_get_timing(ide_hwif_t *hwif)
514{
515 acpi_status status;
516 struct acpi_buffer output;
517 union acpi_object *out_obj;
518
519 if (ide_noacpi)
520 return;
521
522 DEBPRINT("ENTER:\n");
523
524 if (!hwif->acpidata) {
525 DEBPRINT("no ACPI data for %s\n", hwif->name);
526 return;
527 }
528
529 /* Setting up output buffer for _GTM */
530 output.length = ACPI_ALLOCATE_BUFFER;
531 output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
532
533 /* _GTM has no input parameters */
534 status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_GTM",
535 NULL, &output);
536
537 DEBPRINT("_GTM status: %d, outptr: 0x%p, outlen: 0x%llx\n",
538 status, output.pointer,
539 (unsigned long long)output.length);
540
541 if (ACPI_FAILURE(status)) {
542 DEBPRINT("Run _GTM error: status = 0x%x\n", status);
543 return;
544 }
545
546 if (!output.length || !output.pointer) {
547 DEBPRINT("Run _GTM: length or ptr is NULL (0x%llx, 0x%p)\n",
548 (unsigned long long)output.length,
549 output.pointer);
550 kfree(output.pointer);
551 return;
552 }
553
554 out_obj = output.pointer;
555 if (out_obj->type != ACPI_TYPE_BUFFER) {
556 kfree(output.pointer);
557 DEBPRINT("Run _GTM: error: "
558 "expected object type of ACPI_TYPE_BUFFER, "
559 "got 0x%x\n", out_obj->type);
560 return;
561 }
562
563 if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
564 out_obj->buffer.length != sizeof(struct GTM_buffer)) {
565 kfree(output.pointer);
566 printk(KERN_ERR
Andrew Morton1e8f34f2007-02-07 18:19:42 +0100567 "%s: unexpected _GTM length (0x%x)[should be 0x%zx] or "
568 "addr (0x%p)\n",
569 __FUNCTION__, out_obj->buffer.length,
570 sizeof(struct GTM_buffer), out_obj->buffer.pointer);
Hannes Reineckee3a59b42007-02-07 18:19:37 +0100571 return;
572 }
573
574 memcpy(&hwif->acpidata->gtm, out_obj->buffer.pointer,
575 sizeof(struct GTM_buffer));
576
577 DEBPRINT("_GTM info: ptr: 0x%p, len: 0x%x, exp.len: 0x%Zx\n",
578 out_obj->buffer.pointer, out_obj->buffer.length,
579 sizeof(struct GTM_buffer));
580
581 DEBPRINT("_GTM fields: 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
582 hwif->acpidata->gtm.PIO_speed0,
583 hwif->acpidata->gtm.DMA_speed0,
584 hwif->acpidata->gtm.PIO_speed1,
585 hwif->acpidata->gtm.DMA_speed1,
586 hwif->acpidata->gtm.GTM_flags);
587
588 kfree(output.pointer);
589}
590EXPORT_SYMBOL_GPL(ide_acpi_get_timing);
591
592/**
593 * ide_acpi_push_timing - set the channel (controller) timings
594 * @hwif: target IDE interface (channel)
595 *
596 * This function executes the _STM ACPI method for the target channel.
597 *
598 * _STM requires Identify Drive data, which has to passed as an argument.
599 * Unfortunately hd_driveid is a mangled version which we can't readily
600 * use; hence we'll get the information afresh.
601 */
602void ide_acpi_push_timing(ide_hwif_t *hwif)
603{
604 acpi_status status;
605 struct acpi_object_list input;
606 union acpi_object in_params[3];
607 struct ide_acpi_drive_link *master = &hwif->acpidata->master;
608 struct ide_acpi_drive_link *slave = &hwif->acpidata->slave;
609
610 if (ide_noacpi)
611 return;
612
613 DEBPRINT("ENTER:\n");
614
615 if (!hwif->acpidata) {
616 DEBPRINT("no ACPI data for %s\n", hwif->name);
617 return;
618 }
619
620 /* Give the GTM buffer + drive Identify data to the channel via the
621 * _STM method: */
622 /* setup input parameters buffer for _STM */
623 input.count = 3;
624 input.pointer = in_params;
625 in_params[0].type = ACPI_TYPE_BUFFER;
626 in_params[0].buffer.length = sizeof(struct GTM_buffer);
627 in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm;
628 in_params[1].type = ACPI_TYPE_BUFFER;
629 in_params[1].buffer.length = sizeof(struct hd_driveid);
630 in_params[1].buffer.pointer = (u8 *)&master->idbuff;
631 in_params[2].type = ACPI_TYPE_BUFFER;
632 in_params[2].buffer.length = sizeof(struct hd_driveid);
633 in_params[2].buffer.pointer = (u8 *)&slave->idbuff;
634 /* Output buffer: _STM has no output */
635
636 status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_STM",
637 &input, NULL);
638
639 if (ACPI_FAILURE(status)) {
640 DEBPRINT("Run _STM error: status = 0x%x\n", status);
641 }
642 DEBPRINT("_STM status: %d\n", status);
643}
644EXPORT_SYMBOL_GPL(ide_acpi_push_timing);
645
646/**
Shaohua Li5e321322007-10-11 23:53:58 +0200647 * ide_acpi_set_state - set the channel power state
648 * @hwif: target IDE interface
649 * @on: state, on/off
650 *
651 * This function executes the _PS0/_PS3 ACPI method to set the power state.
652 * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
653 */
654void ide_acpi_set_state(ide_hwif_t *hwif, int on)
655{
656 int unit;
657
Shaohua Li90494892008-01-10 23:03:42 +0100658 if (ide_noacpi || ide_noacpi_psx)
Shaohua Li5e321322007-10-11 23:53:58 +0200659 return;
660
661 DEBPRINT("ENTER:\n");
662
663 if (!hwif->acpidata) {
664 DEBPRINT("no ACPI data for %s\n", hwif->name);
665 return;
666 }
667 /* channel first and then drives for power on and verse versa for power off */
668 if (on)
669 acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0);
670 for (unit = 0; unit < MAX_DRIVES; ++unit) {
671 ide_drive_t *drive = &hwif->drives[unit];
672
673 if (!drive->acpidata->obj_handle)
674 drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
675
676 if (drive->acpidata->obj_handle && drive->present) {
677 acpi_bus_set_power(drive->acpidata->obj_handle,
678 on? ACPI_STATE_D0: ACPI_STATE_D3);
679 }
680 }
681 if (!on)
682 acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D3);
683}
Shaohua Li5e321322007-10-11 23:53:58 +0200684
685/**
Hannes Reineckee3a59b42007-02-07 18:19:37 +0100686 * ide_acpi_init - initialize the ACPI link for an IDE interface
687 * @hwif: target IDE interface (channel)
688 *
689 * The ACPI spec is not quite clear when the drive identify buffer
690 * should be obtained. Calling IDENTIFY DEVICE during shutdown
691 * is not the best of ideas as the drive might already being put to
692 * sleep. And obviously we can't call it during resume.
693 * So we get the information during startup; but this means that
694 * any changes during run-time will be lost after resume.
695 */
696void ide_acpi_init(ide_hwif_t *hwif)
697{
698 int unit;
699 int err;
700 struct ide_acpi_drive_link *master;
701 struct ide_acpi_drive_link *slave;
702
Shaohua Li90494892008-01-10 23:03:42 +0100703 ide_acpi_blacklist();
704
Hannes Reineckee3a59b42007-02-07 18:19:37 +0100705 hwif->acpidata = kzalloc(sizeof(struct ide_acpi_hwif_link), GFP_KERNEL);
706 if (!hwif->acpidata)
707 return;
708
709 hwif->acpidata->obj_handle = ide_acpi_hwif_get_handle(hwif);
710 if (!hwif->acpidata->obj_handle) {
711 DEBPRINT("no ACPI object for %s found\n", hwif->name);
712 kfree(hwif->acpidata);
713 hwif->acpidata = NULL;
714 return;
715 }
716
717 /*
718 * The ACPI spec mandates that we send information
719 * for both drives, regardless whether they are connected
720 * or not.
721 */
722 hwif->acpidata->master.drive = &hwif->drives[0];
723 hwif->drives[0].acpidata = &hwif->acpidata->master;
724 master = &hwif->acpidata->master;
725
726 hwif->acpidata->slave.drive = &hwif->drives[1];
727 hwif->drives[1].acpidata = &hwif->acpidata->slave;
728 slave = &hwif->acpidata->slave;
729
730
731 /*
732 * Send IDENTIFY for each drive
733 */
734 if (master->drive->present) {
735 err = taskfile_lib_get_identify(master->drive, master->idbuff);
736 if (err) {
737 DEBPRINT("identify device %s failed (%d)\n",
738 master->drive->name, err);
739 }
740 }
741
742 if (slave->drive->present) {
743 err = taskfile_lib_get_identify(slave->drive, slave->idbuff);
744 if (err) {
745 DEBPRINT("identify device %s failed (%d)\n",
746 slave->drive->name, err);
747 }
748 }
749
750 if (ide_noacpionboot) {
751 DEBPRINT("ACPI methods disabled on boot\n");
752 return;
753 }
754
Shaohua Li5e321322007-10-11 23:53:58 +0200755 /* ACPI _PS0 before _STM */
756 ide_acpi_set_state(hwif, 1);
Hannes Reineckee3a59b42007-02-07 18:19:37 +0100757 /*
758 * ACPI requires us to call _STM on startup
759 */
760 ide_acpi_get_timing(hwif);
761 ide_acpi_push_timing(hwif);
762
763 for (unit = 0; unit < MAX_DRIVES; ++unit) {
764 ide_drive_t *drive = &hwif->drives[unit];
765
766 if (drive->present) {
767 /* Execute ACPI startup code */
768 ide_acpi_exec_tfs(drive);
769 }
770 }
771}
772EXPORT_SYMBOL_GPL(ide_acpi_init);