Pull ec into release branch
[pandora-kernel.git] / drivers / ata / libata-acpi.c
1 /*
2  * libata-acpi.c
3  * Provides ACPI support for PATA/SATA.
4  *
5  * Copyright (C) 2006 Intel Corp.
6  * Copyright (C) 2006 Randy Dunlap
7  */
8
9 #include <linux/ata.h>
10 #include <linux/delay.h>
11 #include <linux/device.h>
12 #include <linux/errno.h>
13 #include <linux/kernel.h>
14 #include <linux/acpi.h>
15 #include <linux/libata.h>
16 #include <linux/pci.h>
17 #include "libata.h"
18
19 #include <acpi/acpi_bus.h>
20 #include <acpi/acnames.h>
21 #include <acpi/acnamesp.h>
22 #include <acpi/acparser.h>
23 #include <acpi/acexcep.h>
24 #include <acpi/acmacros.h>
25 #include <acpi/actypes.h>
26
27 #define SATA_ROOT_PORT(x)       (((x) >> 16) & 0xffff)
28 #define SATA_PORT_NUMBER(x)     ((x) & 0xffff)  /* or NO_PORT_MULT */
29 #define NO_PORT_MULT            0xffff
30 #define SATA_ADR_RSVD           0xffffffff
31
32 #define REGS_PER_GTF            7
33 struct taskfile_array {
34         u8      tfa[REGS_PER_GTF];      /* regs. 0x1f1 - 0x1f7 */
35 };
36
37 /*
38  *      Helper - belongs in the PCI layer somewhere eventually
39  */
40 static int is_pci_dev(struct device *dev)
41 {
42         return (dev->bus == &pci_bus_type);
43 }
44
45 /**
46  * sata_get_dev_handle - finds acpi_handle and PCI device.function
47  * @dev: device to locate
48  * @handle: returned acpi_handle for @dev
49  * @pcidevfn: return PCI device.func for @dev
50  *
51  * This function is somewhat SATA-specific.  Or at least the
52  * PATA & SATA versions of this function are different,
53  * so it's not entirely generic code.
54  *
55  * Returns 0 on success, <0 on error.
56  */
57 static int sata_get_dev_handle(struct device *dev, acpi_handle *handle,
58                                         acpi_integer *pcidevfn)
59 {
60         struct pci_dev  *pci_dev;
61         acpi_integer    addr;
62
63         if (!is_pci_dev(dev))
64                 return -ENODEV;
65
66         pci_dev = to_pci_dev(dev);      /* NOTE: PCI-specific */
67         /* Please refer to the ACPI spec for the syntax of _ADR. */
68         addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
69         *pcidevfn = addr;
70         *handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
71         if (!*handle)
72                 return -ENODEV;
73         return 0;
74 }
75
76 /**
77  * pata_get_dev_handle - finds acpi_handle and PCI device.function
78  * @dev: device to locate
79  * @handle: returned acpi_handle for @dev
80  * @pcidevfn: return PCI device.func for @dev
81  *
82  * The PATA and SATA versions of this function are different.
83  *
84  * Returns 0 on success, <0 on error.
85  */
86 static int pata_get_dev_handle(struct device *dev, acpi_handle *handle,
87                                 acpi_integer *pcidevfn)
88 {
89         unsigned int bus, devnum, func;
90         acpi_integer addr;
91         acpi_handle dev_handle, parent_handle;
92         struct acpi_buffer buffer = {.length = ACPI_ALLOCATE_BUFFER,
93                                         .pointer = NULL};
94         acpi_status status;
95         struct acpi_device_info *dinfo = NULL;
96         int ret = -ENODEV;
97         struct pci_dev *pdev;
98
99         if (!is_pci_dev(dev))
100                 return -ENODEV;
101
102         pdev = to_pci_dev(dev);
103
104         bus = pdev->bus->number;
105         devnum = PCI_SLOT(pdev->devfn);
106         func = PCI_FUNC(pdev->devfn);
107
108         dev_handle = DEVICE_ACPI_HANDLE(dev);
109         parent_handle = DEVICE_ACPI_HANDLE(dev->parent);
110
111         status = acpi_get_object_info(parent_handle, &buffer);
112         if (ACPI_FAILURE(status))
113                 goto err;
114
115         dinfo = buffer.pointer;
116         if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
117             dinfo->address == bus) {
118                 /* ACPI spec for _ADR for PCI bus: */
119                 addr = (acpi_integer)(devnum << 16 | func);
120                 *pcidevfn = addr;
121                 *handle = dev_handle;
122         } else {
123                 goto err;
124         }
125
126         if (!*handle)
127                 goto err;
128         ret = 0;
129 err:
130         kfree(dinfo);
131         return ret;
132 }
133
134 struct walk_info {              /* can be trimmed some */
135         struct device   *dev;
136         struct acpi_device *adev;
137         acpi_handle     handle;
138         acpi_integer    pcidevfn;
139         unsigned int    drivenum;
140         acpi_handle     obj_handle;
141         struct ata_port *ataport;
142         struct ata_device *atadev;
143         u32             sata_adr;
144         int             status;
145         char            basepath[ACPI_PATHNAME_MAX];
146         int             basepath_len;
147 };
148
149 static acpi_status get_devices(acpi_handle handle,
150                                 u32 level, void *context, void **return_value)
151 {
152         acpi_status             status;
153         struct walk_info        *winfo = context;
154         struct acpi_buffer      namebuf = {ACPI_ALLOCATE_BUFFER, NULL};
155         char                    *pathname;
156         struct acpi_buffer      buffer;
157         struct acpi_device_info *dinfo;
158
159         status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &namebuf);
160         if (status)
161                 goto ret;
162         pathname = namebuf.pointer;
163
164         buffer.length = ACPI_ALLOCATE_BUFFER;
165         buffer.pointer = NULL;
166         status = acpi_get_object_info(handle, &buffer);
167         if (ACPI_FAILURE(status))
168                 goto out2;
169
170         dinfo = buffer.pointer;
171
172         /* find full device path name for pcidevfn */
173         if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
174             dinfo->address == winfo->pcidevfn) {
175                 if (ata_msg_probe(winfo->ataport))
176                         ata_dev_printk(winfo->atadev, KERN_DEBUG,
177                                 ":%s: matches pcidevfn (0x%llx)\n",
178                                 pathname, winfo->pcidevfn);
179                 strlcpy(winfo->basepath, pathname,
180                         sizeof(winfo->basepath));
181                 winfo->basepath_len = strlen(pathname);
182                 goto out;
183         }
184
185         /* if basepath is not yet known, ignore this object */
186         if (!winfo->basepath_len)
187                 goto out;
188
189         /* if this object is in scope of basepath, maybe use it */
190         if (strncmp(pathname, winfo->basepath,
191             winfo->basepath_len) == 0) {
192                 if (!(dinfo->valid & ACPI_VALID_ADR))
193                         goto out;
194                 if (ata_msg_probe(winfo->ataport))
195                         ata_dev_printk(winfo->atadev, KERN_DEBUG,
196                                 "GOT ONE: (%s) root_port = 0x%llx,"
197                                 " port_num = 0x%llx\n", pathname,
198                                 SATA_ROOT_PORT(dinfo->address),
199                                 SATA_PORT_NUMBER(dinfo->address));
200                 /* heuristics: */
201                 if (SATA_PORT_NUMBER(dinfo->address) != NO_PORT_MULT)
202                         if (ata_msg_probe(winfo->ataport))
203                                 ata_dev_printk(winfo->atadev,
204                                         KERN_DEBUG, "warning: don't"
205                                         " know how to handle SATA port"
206                                         " multiplier\n");
207                 if (SATA_ROOT_PORT(dinfo->address) ==
208                         winfo->ataport->port_no &&
209                     SATA_PORT_NUMBER(dinfo->address) == NO_PORT_MULT) {
210                         if (ata_msg_probe(winfo->ataport))
211                                 ata_dev_printk(winfo->atadev,
212                                         KERN_DEBUG,
213                                         "THIS ^^^^^ is the requested"
214                                         " SATA drive (handle = 0x%p)\n",
215                                         handle);
216                         winfo->sata_adr = dinfo->address;
217                         winfo->obj_handle = handle;
218                 }
219         }
220 out:
221         kfree(dinfo);
222 out2:
223         kfree(pathname);
224
225 ret:
226         return status;
227 }
228
229 /* Get the SATA drive _ADR object. */
230 static int get_sata_adr(struct device *dev, acpi_handle handle,
231                         acpi_integer pcidevfn, unsigned int drive,
232                         struct ata_port *ap,
233                         struct ata_device *atadev, u32 *dev_adr)
234 {
235         acpi_status     status;
236         struct walk_info *winfo;
237         int             err = -ENOMEM;
238
239         winfo = kzalloc(sizeof(struct walk_info), GFP_KERNEL);
240         if (!winfo)
241                 goto out;
242
243         winfo->dev = dev;
244         winfo->atadev = atadev;
245         winfo->ataport = ap;
246         if (acpi_bus_get_device(handle, &winfo->adev) < 0)
247                 if (ata_msg_probe(ap))
248                         ata_dev_printk(winfo->atadev, KERN_DEBUG,
249                                 "acpi_bus_get_device failed\n");
250         winfo->handle = handle;
251         winfo->pcidevfn = pcidevfn;
252         winfo->drivenum = drive;
253
254         status = acpi_get_devices(NULL, get_devices, winfo, NULL);
255         if (ACPI_FAILURE(status)) {
256                 if (ata_msg_probe(ap))
257                         ata_dev_printk(winfo->atadev, KERN_DEBUG,
258                                 "%s: acpi_get_devices failed\n",
259                                 __FUNCTION__);
260                 err = -ENODEV;
261         } else {
262                 *dev_adr = winfo->sata_adr;
263                 atadev->obj_handle = winfo->obj_handle;
264                 err = 0;
265         }
266         kfree(winfo);
267 out:
268         return err;
269 }
270
271 /**
272  * do_drive_get_GTF - get the drive bootup default taskfile settings
273  * @ap: the ata_port for the drive
274  * @ix: target ata_device (drive) index
275  * @gtf_length: number of bytes of _GTF data returned at @gtf_address
276  * @gtf_address: buffer containing _GTF taskfile arrays
277  *
278  * This applies to both PATA and SATA drives.
279  *
280  * The _GTF method has no input parameters.
281  * It returns a variable number of register set values (registers
282  * hex 1F1..1F7, taskfiles).
283  * The <variable number> is not known in advance, so have ACPI-CA
284  * allocate the buffer as needed and return it, then free it later.
285  *
286  * The returned @gtf_length and @gtf_address are only valid if the
287  * function return value is 0.
288  */
289 static int do_drive_get_GTF(struct ata_port *ap, int ix,
290                         unsigned int *gtf_length, unsigned long *gtf_address,
291                         unsigned long *obj_loc)
292 {
293         acpi_status                     status;
294         acpi_handle                     dev_handle = NULL;
295         acpi_handle                     chan_handle, drive_handle;
296         acpi_integer                    pcidevfn = 0;
297         u32                             dev_adr;
298         struct acpi_buffer              output;
299         union acpi_object               *out_obj;
300         struct device                   *dev = ap->host->dev;
301         struct ata_device               *atadev = &ap->device[ix];
302         int                             err = -ENODEV;
303
304         *gtf_length = 0;
305         *gtf_address = 0UL;
306         *obj_loc = 0UL;
307
308         if (libata_noacpi)
309                 return 0;
310
311         if (ata_msg_probe(ap))
312                 ata_dev_printk(atadev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
313                                __FUNCTION__, ap->port_no);
314
315         if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED)) {
316                 if (ata_msg_probe(ap))
317                         ata_dev_printk(atadev, KERN_DEBUG, "%s: ERR: "
318                                 "ata_dev_present: %d, PORT_DISABLED: %lu\n",
319                                 __FUNCTION__, ata_dev_enabled(atadev),
320                                 ap->flags & ATA_FLAG_DISABLED);
321                 goto out;
322         }
323
324         /* Don't continue if device has no _ADR method.
325          * _GTF is intended for known motherboard devices. */
326         if (!(ap->cbl == ATA_CBL_SATA)) {
327                 err = pata_get_dev_handle(dev, &dev_handle, &pcidevfn);
328                 if (err < 0) {
329                         if (ata_msg_probe(ap))
330                                 ata_dev_printk(atadev, KERN_DEBUG,
331                                         "%s: pata_get_dev_handle failed (%d)\n",
332                                         __FUNCTION__, err);
333                         goto out;
334                 }
335         } else {
336                 err = sata_get_dev_handle(dev, &dev_handle, &pcidevfn);
337                 if (err < 0) {
338                         if (ata_msg_probe(ap))
339                                 ata_dev_printk(atadev, KERN_DEBUG,
340                                         "%s: sata_get_dev_handle failed (%d\n",
341                                         __FUNCTION__, err);
342                         goto out;
343                 }
344         }
345
346         /* Get this drive's _ADR info. if not already known. */
347         if (!atadev->obj_handle) {
348                 if (!(ap->cbl == ATA_CBL_SATA)) {
349                         /* get child objects of dev_handle == channel objects,
350                          * + _their_ children == drive objects */
351                         /* channel is ap->port_no */
352                         chan_handle = acpi_get_child(dev_handle,
353                                                 ap->port_no);
354                         if (ata_msg_probe(ap))
355                                 ata_dev_printk(atadev, KERN_DEBUG,
356                                         "%s: chan adr=%d: chan_handle=0x%p\n",
357                                         __FUNCTION__, ap->port_no,
358                                         chan_handle);
359                         if (!chan_handle) {
360                                 err = -ENODEV;
361                                 goto out;
362                         }
363                         /* TBD: could also check ACPI object VALID bits */
364                         drive_handle = acpi_get_child(chan_handle, ix);
365                         if (!drive_handle) {
366                                 err = -ENODEV;
367                                 goto out;
368                         }
369                         dev_adr = ix;
370                         atadev->obj_handle = drive_handle;
371                 } else {        /* for SATA mode */
372                         dev_adr = SATA_ADR_RSVD;
373                         err = get_sata_adr(dev, dev_handle, pcidevfn, 0,
374                                         ap, atadev, &dev_adr);
375                 }
376                 if (err < 0 || dev_adr == SATA_ADR_RSVD ||
377                     !atadev->obj_handle) {
378                         if (ata_msg_probe(ap))
379                                 ata_dev_printk(atadev, KERN_DEBUG,
380                                         "%s: get_sata/pata_adr failed: "
381                                         "err=%d, dev_adr=%u, obj_handle=0x%p\n",
382                                         __FUNCTION__, err, dev_adr,
383                                         atadev->obj_handle);
384                         goto out;
385                 }
386         }
387
388         /* Setting up output buffer */
389         output.length = ACPI_ALLOCATE_BUFFER;
390         output.pointer = NULL;  /* ACPI-CA sets this; save/free it later */
391
392         /* _GTF has no input parameters */
393         err = -EIO;
394         status = acpi_evaluate_object(atadev->obj_handle, "_GTF",
395                                         NULL, &output);
396         if (ACPI_FAILURE(status)) {
397                 if (ata_msg_probe(ap))
398                         ata_dev_printk(atadev, KERN_DEBUG,
399                                 "%s: Run _GTF error: status = 0x%x\n",
400                                 __FUNCTION__, status);
401                 goto out;
402         }
403
404         if (!output.length || !output.pointer) {
405                 if (ata_msg_probe(ap))
406                         ata_dev_printk(atadev, KERN_DEBUG, "%s: Run _GTF: "
407                                 "length or ptr is NULL (0x%llx, 0x%p)\n",
408                                 __FUNCTION__,
409                                 (unsigned long long)output.length,
410                                 output.pointer);
411                 kfree(output.pointer);
412                 goto out;
413         }
414
415         out_obj = output.pointer;
416         if (out_obj->type != ACPI_TYPE_BUFFER) {
417                 kfree(output.pointer);
418                 if (ata_msg_probe(ap))
419                         ata_dev_printk(atadev, KERN_DEBUG, "%s: Run _GTF: "
420                                 "error: expected object type of "
421                                 " ACPI_TYPE_BUFFER, got 0x%x\n",
422                                 __FUNCTION__, out_obj->type);
423                 err = -ENOENT;
424                 goto out;
425         }
426
427         if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
428             out_obj->buffer.length % REGS_PER_GTF) {
429                 if (ata_msg_drv(ap))
430                         ata_dev_printk(atadev, KERN_ERR,
431                                 "%s: unexpected GTF length (%d) or addr (0x%p)\n",
432                                 __FUNCTION__, out_obj->buffer.length,
433                                 out_obj->buffer.pointer);
434                 err = -ENOENT;
435                 goto out;
436         }
437
438         *gtf_length = out_obj->buffer.length;
439         *gtf_address = (unsigned long)out_obj->buffer.pointer;
440         *obj_loc = (unsigned long)out_obj;
441         if (ata_msg_probe(ap))
442                 ata_dev_printk(atadev, KERN_DEBUG, "%s: returning "
443                         "gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
444                         __FUNCTION__, *gtf_length, *gtf_address, *obj_loc);
445         err = 0;
446 out:
447         return err;
448 }
449
450 /**
451  * taskfile_load_raw - send taskfile registers to host controller
452  * @ap: Port to which output is sent
453  * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
454  *
455  * Outputs ATA taskfile to standard ATA host controller using MMIO
456  * or PIO as indicated by the ATA_FLAG_MMIO flag.
457  * Writes the control, feature, nsect, lbal, lbam, and lbah registers.
458  * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,
459  * hob_lbal, hob_lbam, and hob_lbah.
460  *
461  * This function waits for idle (!BUSY and !DRQ) after writing
462  * registers.  If the control register has a new value, this
463  * function also waits for idle after writing control and before
464  * writing the remaining registers.
465  *
466  * LOCKING: TBD:
467  * Inherited from caller.
468  */
469 static void taskfile_load_raw(struct ata_port *ap,
470                                 struct ata_device *atadev,
471                                 const struct taskfile_array *gtf)
472 {
473         struct ata_taskfile tf;
474         unsigned int err;
475
476         if (ata_msg_probe(ap))
477                 ata_dev_printk(atadev, KERN_DEBUG, "%s: (0x1f1-1f7): hex: "
478                         "%02x %02x %02x %02x %02x %02x %02x\n",
479                         __FUNCTION__,
480                         gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
481                         gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
482
483         if ((gtf->tfa[0] == 0) && (gtf->tfa[1] == 0) && (gtf->tfa[2] == 0)
484             && (gtf->tfa[3] == 0) && (gtf->tfa[4] == 0) && (gtf->tfa[5] == 0)
485             && (gtf->tfa[6] == 0))
486                 return;
487
488         ata_tf_init(atadev, &tf);
489
490         /* convert gtf to tf */
491         tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */
492         tf.protocol = atadev->class == ATA_DEV_ATAPI ?
493                 ATA_PROT_ATAPI_NODATA : ATA_PROT_NODATA;
494         tf.feature = gtf->tfa[0];       /* 0x1f1 */
495         tf.nsect   = gtf->tfa[1];       /* 0x1f2 */
496         tf.lbal    = gtf->tfa[2];       /* 0x1f3 */
497         tf.lbam    = gtf->tfa[3];       /* 0x1f4 */
498         tf.lbah    = gtf->tfa[4];       /* 0x1f5 */
499         tf.device  = gtf->tfa[5];       /* 0x1f6 */
500         tf.command = gtf->tfa[6];       /* 0x1f7 */
501
502         err = ata_exec_internal(atadev, &tf, NULL, DMA_NONE, NULL, 0);
503         if (err && ata_msg_probe(ap))
504                 ata_dev_printk(atadev, KERN_ERR,
505                         "%s: ata_exec_internal failed: %u\n",
506                         __FUNCTION__, err);
507 }
508
509 /**
510  * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
511  * @ap: the ata_port for the drive
512  * @atadev: target ata_device
513  * @gtf_length: total number of bytes of _GTF taskfiles
514  * @gtf_address: location of _GTF taskfile arrays
515  *
516  * This applies to both PATA and SATA drives.
517  *
518  * Write {gtf_address, length gtf_length} in groups of
519  * REGS_PER_GTF bytes.
520  */
521 static int do_drive_set_taskfiles(struct ata_port *ap,
522                 struct ata_device *atadev, unsigned int gtf_length,
523                 unsigned long gtf_address)
524 {
525         int                     err = -ENODEV;
526         int                     gtf_count = gtf_length / REGS_PER_GTF;
527         int                     ix;
528         struct taskfile_array   *gtf;
529
530         if (ata_msg_probe(ap))
531                 ata_dev_printk(atadev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
532                                __FUNCTION__, ap->port_no);
533
534         if (libata_noacpi || !(ap->cbl == ATA_CBL_SATA))
535                 return 0;
536
537         if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED))
538                 goto out;
539         if (!gtf_count)         /* shouldn't be here */
540                 goto out;
541
542         if (gtf_length % REGS_PER_GTF) {
543                 if (ata_msg_drv(ap))
544                         ata_dev_printk(atadev, KERN_ERR,
545                                 "%s: unexpected GTF length (%d)\n",
546                                 __FUNCTION__, gtf_length);
547                 goto out;
548         }
549
550         for (ix = 0; ix < gtf_count; ix++) {
551                 gtf = (struct taskfile_array *)
552                         (gtf_address + ix * REGS_PER_GTF);
553
554                 /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
555                 taskfile_load_raw(ap, atadev, gtf);
556         }
557
558         err = 0;
559 out:
560         return err;
561 }
562
563 /**
564  * ata_acpi_exec_tfs - get then write drive taskfile settings
565  * @ap: the ata_port for the drive
566  *
567  * This applies to both PATA and SATA drives.
568  */
569 int ata_acpi_exec_tfs(struct ata_port *ap)
570 {
571         int             ix;
572         int             ret =0;
573         unsigned int    gtf_length;
574         unsigned long   gtf_address;
575         unsigned long   obj_loc;
576
577         if (libata_noacpi)
578                 return 0;
579         /*
580          * TBD - implement PATA support.  For now,
581          * we should not run GTF on PATA devices since some
582          * PATA require execution of GTM/STM before GTF.
583          */
584         if (!(ap->cbl == ATA_CBL_SATA))
585                 return 0;
586
587         for (ix = 0; ix < ATA_MAX_DEVICES; ix++) {
588                 if (!ata_dev_enabled(&ap->device[ix]))
589                         continue;
590
591                 ret = do_drive_get_GTF(ap, ix,
592                                 &gtf_length, &gtf_address, &obj_loc);
593                 if (ret < 0) {
594                         if (ata_msg_probe(ap))
595                                 ata_port_printk(ap, KERN_DEBUG,
596                                         "%s: get_GTF error (%d)\n",
597                                         __FUNCTION__, ret);
598                         break;
599                 }
600
601                 ret = do_drive_set_taskfiles(ap, &ap->device[ix],
602                                 gtf_length, gtf_address);
603                 kfree((void *)obj_loc);
604                 if (ret < 0) {
605                         if (ata_msg_probe(ap))
606                                 ata_port_printk(ap, KERN_DEBUG,
607                                         "%s: set_taskfiles error (%d)\n",
608                                         __FUNCTION__, ret);
609                         break;
610                 }
611         }
612
613         return ret;
614 }
615
616 /**
617  * ata_acpi_push_id - send Identify data to drive
618  * @ap: the ata_port for the drive
619  * @ix: drive index
620  *
621  * _SDD ACPI object: for SATA mode only
622  * Must be after Identify (Packet) Device -- uses its data
623  * ATM this function never returns a failure.  It is an optional
624  * method and if it fails for whatever reason, we should still
625  * just keep going.
626  */
627 int ata_acpi_push_id(struct ata_port *ap, unsigned int ix)
628 {
629         acpi_handle                     handle;
630         acpi_integer                    pcidevfn;
631         int                             err;
632         struct device                   *dev = ap->host->dev;
633         struct ata_device               *atadev = &ap->device[ix];
634         u32                             dev_adr;
635         acpi_status                     status;
636         struct acpi_object_list         input;
637         union acpi_object               in_params[1];
638
639         if (libata_noacpi)
640                 return 0;
641
642         if (ata_msg_probe(ap))
643                 ata_dev_printk(atadev, KERN_DEBUG, "%s: ix = %d, port#: %d\n",
644                                __FUNCTION__, ix, ap->port_no);
645
646         /* Don't continue if not a SATA device. */
647         if (!(ap->cbl == ATA_CBL_SATA)) {
648                 if (ata_msg_probe(ap))
649                         ata_dev_printk(atadev, KERN_DEBUG,
650                                 "%s: Not a SATA device\n", __FUNCTION__);
651                 goto out;
652         }
653
654         /* Don't continue if device has no _ADR method.
655          * _SDD is intended for known motherboard devices. */
656         err = sata_get_dev_handle(dev, &handle, &pcidevfn);
657         if (err < 0) {
658                 if (ata_msg_probe(ap))
659                         ata_dev_printk(atadev, KERN_DEBUG,
660                                 "%s: sata_get_dev_handle failed (%d\n",
661                                 __FUNCTION__, err);
662                 goto out;
663         }
664
665         /* Get this drive's _ADR info, if not already known */
666         if (!atadev->obj_handle) {
667                 dev_adr = SATA_ADR_RSVD;
668                 err = get_sata_adr(dev, handle, pcidevfn, ix, ap, atadev,
669                                         &dev_adr);
670                 if (err < 0 || dev_adr == SATA_ADR_RSVD ||
671                         !atadev->obj_handle) {
672                         if (ata_msg_probe(ap))
673                                 ata_dev_printk(atadev, KERN_DEBUG,
674                                         "%s: get_sata_adr failed: "
675                                         "err=%d, dev_adr=%u, obj_handle=0x%p\n",
676                                         __FUNCTION__, err, dev_adr,
677                                         atadev->obj_handle);
678                         goto out;
679                 }
680         }
681
682         /* Give the drive Identify data to the drive via the _SDD method */
683         /* _SDD: set up input parameters */
684         input.count = 1;
685         input.pointer = in_params;
686         in_params[0].type = ACPI_TYPE_BUFFER;
687         in_params[0].buffer.length = sizeof(atadev->id[0]) * ATA_ID_WORDS;
688         in_params[0].buffer.pointer = (u8 *)atadev->id;
689         /* Output buffer: _SDD has no output */
690
691         /* It's OK for _SDD to be missing too. */
692         swap_buf_le16(atadev->id, ATA_ID_WORDS);
693         status = acpi_evaluate_object(atadev->obj_handle, "_SDD", &input, NULL);
694         swap_buf_le16(atadev->id, ATA_ID_WORDS);
695
696         err = ACPI_FAILURE(status) ? -EIO : 0;
697         if (err < 0) {
698                 if (ata_msg_probe(ap))
699                         ata_dev_printk(atadev, KERN_DEBUG,
700                                        "%s _SDD error: status = 0x%x\n",
701                                        __FUNCTION__, status);
702         }
703
704         /* always return success */
705 out:
706         return 0;
707 }
708
709