]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/ata/libata-acpi.c
Merge branch 'linux-2.6'
[mirror_ubuntu-bionic-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 = ATA_PROT_NODATA;
493 tf.feature = gtf->tfa[0]; /* 0x1f1 */
494 tf.nsect = gtf->tfa[1]; /* 0x1f2 */
495 tf.lbal = gtf->tfa[2]; /* 0x1f3 */
496 tf.lbam = gtf->tfa[3]; /* 0x1f4 */
497 tf.lbah = gtf->tfa[4]; /* 0x1f5 */
498 tf.device = gtf->tfa[5]; /* 0x1f6 */
499 tf.command = gtf->tfa[6]; /* 0x1f7 */
500
501 err = ata_exec_internal(atadev, &tf, NULL, DMA_NONE, NULL, 0);
502 if (err && ata_msg_probe(ap))
503 ata_dev_printk(atadev, KERN_ERR,
504 "%s: ata_exec_internal failed: %u\n",
505 __FUNCTION__, err);
506 }
507
508 /**
509 * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
510 * @ap: the ata_port for the drive
511 * @atadev: target ata_device
512 * @gtf_length: total number of bytes of _GTF taskfiles
513 * @gtf_address: location of _GTF taskfile arrays
514 *
515 * This applies to both PATA and SATA drives.
516 *
517 * Write {gtf_address, length gtf_length} in groups of
518 * REGS_PER_GTF bytes.
519 */
520 static int do_drive_set_taskfiles(struct ata_port *ap,
521 struct ata_device *atadev, unsigned int gtf_length,
522 unsigned long gtf_address)
523 {
524 int err = -ENODEV;
525 int gtf_count = gtf_length / REGS_PER_GTF;
526 int ix;
527 struct taskfile_array *gtf;
528
529 if (ata_msg_probe(ap))
530 ata_dev_printk(atadev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
531 __FUNCTION__, ap->port_no);
532
533 if (libata_noacpi || !(ap->cbl == ATA_CBL_SATA))
534 return 0;
535
536 if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED))
537 goto out;
538 if (!gtf_count) /* shouldn't be here */
539 goto out;
540
541 if (gtf_length % REGS_PER_GTF) {
542 if (ata_msg_drv(ap))
543 ata_dev_printk(atadev, KERN_ERR,
544 "%s: unexpected GTF length (%d)\n",
545 __FUNCTION__, gtf_length);
546 goto out;
547 }
548
549 for (ix = 0; ix < gtf_count; ix++) {
550 gtf = (struct taskfile_array *)
551 (gtf_address + ix * REGS_PER_GTF);
552
553 /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
554 taskfile_load_raw(ap, atadev, gtf);
555 }
556
557 err = 0;
558 out:
559 return err;
560 }
561
562 /**
563 * ata_acpi_exec_tfs - get then write drive taskfile settings
564 * @ap: the ata_port for the drive
565 *
566 * This applies to both PATA and SATA drives.
567 */
568 int ata_acpi_exec_tfs(struct ata_port *ap)
569 {
570 int ix;
571 int ret =0;
572 unsigned int gtf_length;
573 unsigned long gtf_address;
574 unsigned long obj_loc;
575
576 if (libata_noacpi)
577 return 0;
578 /*
579 * TBD - implement PATA support. For now,
580 * we should not run GTF on PATA devices since some
581 * PATA require execution of GTM/STM before GTF.
582 */
583 if (!(ap->cbl == ATA_CBL_SATA))
584 return 0;
585
586 for (ix = 0; ix < ATA_MAX_DEVICES; ix++) {
587 if (!ata_dev_enabled(&ap->device[ix]))
588 continue;
589
590 ret = do_drive_get_GTF(ap, ix,
591 &gtf_length, &gtf_address, &obj_loc);
592 if (ret < 0) {
593 if (ata_msg_probe(ap))
594 ata_port_printk(ap, KERN_DEBUG,
595 "%s: get_GTF error (%d)\n",
596 __FUNCTION__, ret);
597 break;
598 }
599
600 ret = do_drive_set_taskfiles(ap, &ap->device[ix],
601 gtf_length, gtf_address);
602 kfree((void *)obj_loc);
603 if (ret < 0) {
604 if (ata_msg_probe(ap))
605 ata_port_printk(ap, KERN_DEBUG,
606 "%s: set_taskfiles error (%d)\n",
607 __FUNCTION__, ret);
608 break;
609 }
610 }
611
612 return ret;
613 }
614
615 /**
616 * ata_acpi_push_id - send Identify data to drive
617 * @ap: the ata_port for the drive
618 * @ix: drive index
619 *
620 * _SDD ACPI object: for SATA mode only
621 * Must be after Identify (Packet) Device -- uses its data
622 * ATM this function never returns a failure. It is an optional
623 * method and if it fails for whatever reason, we should still
624 * just keep going.
625 */
626 int ata_acpi_push_id(struct ata_port *ap, unsigned int ix)
627 {
628 acpi_handle handle;
629 acpi_integer pcidevfn;
630 int err;
631 struct device *dev = ap->host->dev;
632 struct ata_device *atadev = &ap->device[ix];
633 u32 dev_adr;
634 acpi_status status;
635 struct acpi_object_list input;
636 union acpi_object in_params[1];
637
638 if (libata_noacpi)
639 return 0;
640
641 if (ata_msg_probe(ap))
642 ata_dev_printk(atadev, KERN_DEBUG, "%s: ix = %d, port#: %d\n",
643 __FUNCTION__, ix, ap->port_no);
644
645 /* Don't continue if not a SATA device. */
646 if (!(ap->cbl == ATA_CBL_SATA)) {
647 if (ata_msg_probe(ap))
648 ata_dev_printk(atadev, KERN_DEBUG,
649 "%s: Not a SATA device\n", __FUNCTION__);
650 goto out;
651 }
652
653 /* Don't continue if device has no _ADR method.
654 * _SDD is intended for known motherboard devices. */
655 err = sata_get_dev_handle(dev, &handle, &pcidevfn);
656 if (err < 0) {
657 if (ata_msg_probe(ap))
658 ata_dev_printk(atadev, KERN_DEBUG,
659 "%s: sata_get_dev_handle failed (%d\n",
660 __FUNCTION__, err);
661 goto out;
662 }
663
664 /* Get this drive's _ADR info, if not already known */
665 if (!atadev->obj_handle) {
666 dev_adr = SATA_ADR_RSVD;
667 err = get_sata_adr(dev, handle, pcidevfn, ix, ap, atadev,
668 &dev_adr);
669 if (err < 0 || dev_adr == SATA_ADR_RSVD ||
670 !atadev->obj_handle) {
671 if (ata_msg_probe(ap))
672 ata_dev_printk(atadev, KERN_DEBUG,
673 "%s: get_sata_adr failed: "
674 "err=%d, dev_adr=%u, obj_handle=0x%p\n",
675 __FUNCTION__, err, dev_adr,
676 atadev->obj_handle);
677 goto out;
678 }
679 }
680
681 /* Give the drive Identify data to the drive via the _SDD method */
682 /* _SDD: set up input parameters */
683 input.count = 1;
684 input.pointer = in_params;
685 in_params[0].type = ACPI_TYPE_BUFFER;
686 in_params[0].buffer.length = sizeof(atadev->id[0]) * ATA_ID_WORDS;
687 in_params[0].buffer.pointer = (u8 *)atadev->id;
688 /* Output buffer: _SDD has no output */
689
690 /* It's OK for _SDD to be missing too. */
691 swap_buf_le16(atadev->id, ATA_ID_WORDS);
692 status = acpi_evaluate_object(atadev->obj_handle, "_SDD", &input, NULL);
693 swap_buf_le16(atadev->id, ATA_ID_WORDS);
694
695 err = ACPI_FAILURE(status) ? -EIO : 0;
696 if (err < 0) {
697 if (ata_msg_probe(ap))
698 ata_dev_printk(atadev, KERN_DEBUG,
699 "%s _SDD error: status = 0x%x\n",
700 __FUNCTION__, status);
701 }
702
703 /* always return success */
704 out:
705 return 0;
706 }
707
708