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