]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/ide/ide-acpi.c
ide: sanitize ACPI initialization
[linux-2.6-omap-h63xx.git] / 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         ide_hwif_t                      *hwif = drive->hwif;
223         struct device                   *dev = hwif->gendev.parent;
224         int                             err = -ENODEV;
225         int                             port;
226
227         *gtf_length = 0;
228         *gtf_address = 0UL;
229         *obj_loc = 0UL;
230
231         if (ide_noacpi)
232                 return 0;
233
234         if (!dev) {
235                 DEBPRINT("no PCI device for %s\n", hwif->name);
236                 goto out;
237         }
238
239         if (!hwif->acpidata) {
240                 DEBPRINT("no ACPI data for %s\n", hwif->name);
241                 goto out;
242         }
243
244         port = hwif->channel ? drive->dn - 2: drive->dn;
245
246         DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
247                  hwif->name, dev_name(dev), port, hwif->channel);
248
249         if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) {
250                 DEBPRINT("%s drive %d:%d not present\n",
251                          hwif->name, hwif->channel, port);
252                 goto out;
253         }
254
255         if (!drive->acpidata->obj_handle) {
256                 DEBPRINT("No ACPI object found for %s\n", drive->name);
257                 goto out;
258         }
259
260         /* Setting up output buffer */
261         output.length = ACPI_ALLOCATE_BUFFER;
262         output.pointer = NULL;  /* ACPI-CA sets this; save/free it later */
263
264         /* _GTF has no input parameters */
265         err = -EIO;
266         status = acpi_evaluate_object(drive->acpidata->obj_handle, "_GTF",
267                                       NULL, &output);
268         if (ACPI_FAILURE(status)) {
269                 printk(KERN_DEBUG
270                        "%s: Run _GTF error: status = 0x%x\n",
271                        __func__, status);
272                 goto out;
273         }
274
275         if (!output.length || !output.pointer) {
276                 DEBPRINT("Run _GTF: "
277                        "length or ptr is NULL (0x%llx, 0x%p)\n",
278                        (unsigned long long)output.length,
279                        output.pointer);
280                 goto out;
281         }
282
283         out_obj = output.pointer;
284         if (out_obj->type != ACPI_TYPE_BUFFER) {
285                 DEBPRINT("Run _GTF: error: "
286                        "expected object type of ACPI_TYPE_BUFFER, "
287                        "got 0x%x\n", out_obj->type);
288                 err = -ENOENT;
289                 kfree(output.pointer);
290                 goto out;
291         }
292
293         if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
294             out_obj->buffer.length % REGS_PER_GTF) {
295                 printk(KERN_ERR
296                        "%s: unexpected GTF length (%d) or addr (0x%p)\n",
297                        __func__, out_obj->buffer.length,
298                        out_obj->buffer.pointer);
299                 err = -ENOENT;
300                 kfree(output.pointer);
301                 goto out;
302         }
303
304         *gtf_length = out_obj->buffer.length;
305         *gtf_address = (unsigned long)out_obj->buffer.pointer;
306         *obj_loc = (unsigned long)out_obj;
307         DEBPRINT("returning gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
308                  *gtf_length, *gtf_address, *obj_loc);
309         err = 0;
310 out:
311         return err;
312 }
313
314 /**
315  * taskfile_load_raw - send taskfile registers to drive
316  * @drive: drive to which output is sent
317  * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
318  *
319  * Outputs IDE taskfile to the drive.
320  */
321 static int taskfile_load_raw(ide_drive_t *drive,
322                               const struct taskfile_array *gtf)
323 {
324         ide_task_t args;
325         int err = 0;
326
327         DEBPRINT("(0x1f1-1f7): hex: "
328                "%02x %02x %02x %02x %02x %02x %02x\n",
329                gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
330                gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
331
332         memset(&args, 0, sizeof(ide_task_t));
333
334         /* convert gtf to IDE Taskfile */
335         memcpy(&args.tf_array[7], &gtf->tfa, 7);
336         args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
337
338         if (!ide_acpigtf) {
339                 DEBPRINT("_GTF execution disabled\n");
340                 return err;
341         }
342
343         err = ide_no_data_taskfile(drive, &args);
344         if (err)
345                 printk(KERN_ERR "%s: ide_no_data_taskfile failed: %u\n",
346                        __func__, err);
347
348         return err;
349 }
350
351 /**
352  * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
353  * @drive: the drive to which the taskfile command should be sent
354  * @gtf_length: total number of bytes of _GTF taskfiles
355  * @gtf_address: location of _GTF taskfile arrays
356  *
357  * Write {gtf_address, length gtf_length} in groups of
358  * REGS_PER_GTF bytes.
359  */
360 static int do_drive_set_taskfiles(ide_drive_t *drive,
361                                   unsigned int gtf_length,
362                                   unsigned long gtf_address)
363 {
364         int                     rc = -ENODEV, err;
365         int                     gtf_count = gtf_length / REGS_PER_GTF;
366         int                     ix;
367         struct taskfile_array   *gtf;
368
369         if (ide_noacpi)
370                 return 0;
371
372         DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn);
373
374         if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
375                 goto out;
376
377         if (!gtf_count)         /* shouldn't be here */
378                 goto out;
379
380         DEBPRINT("total GTF bytes=%u (0x%x), gtf_count=%d, addr=0x%lx\n",
381                  gtf_length, gtf_length, gtf_count, gtf_address);
382
383         if (gtf_length % REGS_PER_GTF) {
384                 printk(KERN_ERR "%s: unexpected GTF length (%d)\n",
385                        __func__, gtf_length);
386                 goto out;
387         }
388
389         rc = 0;
390         for (ix = 0; ix < gtf_count; ix++) {
391                 gtf = (struct taskfile_array *)
392                         (gtf_address + ix * REGS_PER_GTF);
393
394                 /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
395                 err = taskfile_load_raw(drive, gtf);
396                 if (err)
397                         rc = err;
398         }
399
400 out:
401         return rc;
402 }
403
404 /**
405  * ide_acpi_exec_tfs - get then write drive taskfile settings
406  * @drive: the drive for which the taskfile settings should be
407  *         written.
408  *
409  * According to the ACPI spec this should be called after _STM
410  * has been evaluated for the interface. Some ACPI vendors interpret
411  * that as a hard requirement and modify the taskfile according
412  * to the Identify Drive information passed down with _STM.
413  * So one should really make sure to call this only after _STM has
414  * been executed.
415  */
416 int ide_acpi_exec_tfs(ide_drive_t *drive)
417 {
418         int             ret;
419         unsigned int    gtf_length;
420         unsigned long   gtf_address;
421         unsigned long   obj_loc;
422
423         if (ide_noacpi)
424                 return 0;
425
426         DEBPRINT("call get_GTF, drive=%s port=%d\n", drive->name, drive->dn);
427
428         ret = do_drive_get_GTF(drive, &gtf_length, &gtf_address, &obj_loc);
429         if (ret < 0) {
430                 DEBPRINT("get_GTF error (%d)\n", ret);
431                 return ret;
432         }
433
434         DEBPRINT("call set_taskfiles, drive=%s\n", drive->name);
435
436         ret = do_drive_set_taskfiles(drive, gtf_length, gtf_address);
437         kfree((void *)obj_loc);
438         if (ret < 0) {
439                 DEBPRINT("set_taskfiles error (%d)\n", ret);
440         }
441
442         DEBPRINT("ret=%d\n", ret);
443
444         return ret;
445 }
446
447 /**
448  * ide_acpi_get_timing - get the channel (controller) timings
449  * @hwif: target IDE interface (channel)
450  *
451  * This function executes the _GTM ACPI method for the target channel.
452  *
453  */
454 void ide_acpi_get_timing(ide_hwif_t *hwif)
455 {
456         acpi_status             status;
457         struct acpi_buffer      output;
458         union acpi_object       *out_obj;
459
460         if (ide_noacpi)
461                 return;
462
463         DEBPRINT("ENTER:\n");
464
465         if (!hwif->acpidata) {
466                 DEBPRINT("no ACPI data for %s\n", hwif->name);
467                 return;
468         }
469
470         /* Setting up output buffer for _GTM */
471         output.length = ACPI_ALLOCATE_BUFFER;
472         output.pointer = NULL;  /* ACPI-CA sets this; save/free it later */
473
474         /* _GTM has no input parameters */
475         status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_GTM",
476                                       NULL, &output);
477
478         DEBPRINT("_GTM status: %d, outptr: 0x%p, outlen: 0x%llx\n",
479                  status, output.pointer,
480                  (unsigned long long)output.length);
481
482         if (ACPI_FAILURE(status)) {
483                 DEBPRINT("Run _GTM error: status = 0x%x\n", status);
484                 return;
485         }
486
487         if (!output.length || !output.pointer) {
488                 DEBPRINT("Run _GTM: length or ptr is NULL (0x%llx, 0x%p)\n",
489                        (unsigned long long)output.length,
490                        output.pointer);
491                 kfree(output.pointer);
492                 return;
493         }
494
495         out_obj = output.pointer;
496         if (out_obj->type != ACPI_TYPE_BUFFER) {
497                 kfree(output.pointer);
498                 DEBPRINT("Run _GTM: error: "
499                        "expected object type of ACPI_TYPE_BUFFER, "
500                        "got 0x%x\n", out_obj->type);
501                 return;
502         }
503
504         if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
505             out_obj->buffer.length != sizeof(struct GTM_buffer)) {
506                 kfree(output.pointer);
507                 printk(KERN_ERR
508                         "%s: unexpected _GTM length (0x%x)[should be 0x%zx] or "
509                         "addr (0x%p)\n",
510                         __func__, out_obj->buffer.length,
511                         sizeof(struct GTM_buffer), out_obj->buffer.pointer);
512                 return;
513         }
514
515         memcpy(&hwif->acpidata->gtm, out_obj->buffer.pointer,
516                sizeof(struct GTM_buffer));
517
518         DEBPRINT("_GTM info: ptr: 0x%p, len: 0x%x, exp.len: 0x%Zx\n",
519                  out_obj->buffer.pointer, out_obj->buffer.length,
520                  sizeof(struct GTM_buffer));
521
522         DEBPRINT("_GTM fields: 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
523                  hwif->acpidata->gtm.PIO_speed0,
524                  hwif->acpidata->gtm.DMA_speed0,
525                  hwif->acpidata->gtm.PIO_speed1,
526                  hwif->acpidata->gtm.DMA_speed1,
527                  hwif->acpidata->gtm.GTM_flags);
528
529         kfree(output.pointer);
530 }
531
532 /**
533  * ide_acpi_push_timing - set the channel (controller) timings
534  * @hwif: target IDE interface (channel)
535  *
536  * This function executes the _STM ACPI method for the target channel.
537  *
538  * _STM requires Identify Drive data, which has to passed as an argument.
539  * Unfortunately drive->id is a mangled version which we can't readily
540  * use; hence we'll get the information afresh.
541  */
542 void ide_acpi_push_timing(ide_hwif_t *hwif)
543 {
544         acpi_status             status;
545         struct acpi_object_list input;
546         union acpi_object       in_params[3];
547         struct ide_acpi_drive_link      *master = &hwif->acpidata->master;
548         struct ide_acpi_drive_link      *slave = &hwif->acpidata->slave;
549
550         if (ide_noacpi)
551                 return;
552
553         DEBPRINT("ENTER:\n");
554
555         if (!hwif->acpidata) {
556                 DEBPRINT("no ACPI data for %s\n", hwif->name);
557                 return;
558         }
559
560         /* Give the GTM buffer + drive Identify data to the channel via the
561          * _STM method: */
562         /* setup input parameters buffer for _STM */
563         input.count = 3;
564         input.pointer = in_params;
565         in_params[0].type = ACPI_TYPE_BUFFER;
566         in_params[0].buffer.length = sizeof(struct GTM_buffer);
567         in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm;
568         in_params[1].type = ACPI_TYPE_BUFFER;
569         in_params[1].buffer.length = ATA_ID_WORDS * 2;
570         in_params[1].buffer.pointer = (u8 *)&master->idbuff;
571         in_params[2].type = ACPI_TYPE_BUFFER;
572         in_params[2].buffer.length = ATA_ID_WORDS * 2;
573         in_params[2].buffer.pointer = (u8 *)&slave->idbuff;
574         /* Output buffer: _STM has no output */
575
576         status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_STM",
577                                       &input, NULL);
578
579         if (ACPI_FAILURE(status)) {
580                 DEBPRINT("Run _STM error: status = 0x%x\n", status);
581         }
582         DEBPRINT("_STM status: %d\n", status);
583 }
584
585 /**
586  * ide_acpi_set_state - set the channel power state
587  * @hwif: target IDE interface
588  * @on: state, on/off
589  *
590  * This function executes the _PS0/_PS3 ACPI method to set the power state.
591  * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
592  */
593 void ide_acpi_set_state(ide_hwif_t *hwif, int on)
594 {
595         ide_drive_t *drive;
596         int i;
597
598         if (ide_noacpi || ide_noacpi_psx)
599                 return;
600
601         DEBPRINT("ENTER:\n");
602
603         if (!hwif->acpidata) {
604                 DEBPRINT("no ACPI data for %s\n", hwif->name);
605                 return;
606         }
607
608         /* channel first and then drives for power on and verse versa for power off */
609         if (on)
610                 acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0);
611
612         ide_port_for_each_present_dev(i, drive, hwif) {
613                 if (drive->acpidata->obj_handle)
614                         acpi_bus_set_power(drive->acpidata->obj_handle,
615                                            on ? ACPI_STATE_D0 : ACPI_STATE_D3);
616         }
617
618         if (!on)
619                 acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D3);
620 }
621
622 /**
623  * ide_acpi_init_port - initialize the ACPI link for an IDE interface
624  * @hwif: target IDE interface (channel)
625  *
626  * The ACPI spec is not quite clear when the drive identify buffer
627  * should be obtained. Calling IDENTIFY DEVICE during shutdown
628  * is not the best of ideas as the drive might already being put to
629  * sleep. And obviously we can't call it during resume.
630  * So we get the information during startup; but this means that
631  * any changes during run-time will be lost after resume.
632  */
633 void ide_acpi_init_port(ide_hwif_t *hwif)
634 {
635         hwif->acpidata = kzalloc(sizeof(struct ide_acpi_hwif_link), GFP_KERNEL);
636         if (!hwif->acpidata)
637                 return;
638
639         hwif->acpidata->obj_handle = ide_acpi_hwif_get_handle(hwif);
640         if (!hwif->acpidata->obj_handle) {
641                 DEBPRINT("no ACPI object for %s found\n", hwif->name);
642                 kfree(hwif->acpidata);
643                 hwif->acpidata = NULL;
644         }
645 }
646
647 void ide_acpi_port_init_devices(ide_hwif_t *hwif)
648 {
649         ide_drive_t *drive;
650         int i, err;
651
652         if (hwif->acpidata == NULL)
653                 return;
654
655         /*
656          * The ACPI spec mandates that we send information
657          * for both drives, regardless whether they are connected
658          * or not.
659          */
660         hwif->devices[0]->acpidata = &hwif->acpidata->master;
661         hwif->devices[1]->acpidata = &hwif->acpidata->slave;
662
663         /* get _ADR info for each device */
664         ide_port_for_each_present_dev(i, drive, hwif) {
665                 acpi_handle dev_handle;
666
667                 DEBPRINT("ENTER: %s at channel#: %d port#: %d\n",
668                          drive->name, hwif->channel, drive->dn & 1);
669
670                 /* TBD: could also check ACPI object VALID bits */
671                 dev_handle = acpi_get_child(hwif->acpidata->obj_handle,
672                                             drive->dn & 1);
673
674                 DEBPRINT("drive %s handle 0x%p\n", drive->name, dev_handle);
675
676                 drive->acpidata->obj_handle = dev_handle;
677         }
678
679         /* send IDENTIFY for each device */
680         ide_port_for_each_present_dev(i, drive, hwif) {
681                 err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff);
682                 if (err)
683                         DEBPRINT("identify device %s failed (%d)\n",
684                                  drive->name, err);
685         }
686
687         if (!ide_acpionboot) {
688                 DEBPRINT("ACPI methods disabled on boot\n");
689                 return;
690         }
691
692         /* ACPI _PS0 before _STM */
693         ide_acpi_set_state(hwif, 1);
694         /*
695          * ACPI requires us to call _STM on startup
696          */
697         ide_acpi_get_timing(hwif);
698         ide_acpi_push_timing(hwif);
699
700         ide_port_for_each_present_dev(i, drive, hwif) {
701                 ide_acpi_exec_tfs(drive);
702         }
703 }