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