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