]>
Commit | Line | Data |
---|---|---|
11ef697b KCA |
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)) | |
878d4fed TH |
297 | ata_dev_printk(atadev, KERN_DEBUG, "%s: ENTER: port#: %d\n", |
298 | __FUNCTION__, ap->port_no); | |
11ef697b KCA |
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 | if (ata_msg_probe(ap)) | |
459 | ata_dev_printk(atadev, KERN_DEBUG, "%s: (0x1f1-1f7): hex: " | |
460 | "%02x %02x %02x %02x %02x %02x %02x\n", | |
461 | __FUNCTION__, | |
462 | gtf->tfa[0], gtf->tfa[1], gtf->tfa[2], | |
463 | gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]); | |
464 | ||
465 | if ((gtf->tfa[0] == 0) && (gtf->tfa[1] == 0) && (gtf->tfa[2] == 0) | |
466 | && (gtf->tfa[3] == 0) && (gtf->tfa[4] == 0) && (gtf->tfa[5] == 0) | |
467 | && (gtf->tfa[6] == 0)) | |
468 | return; | |
469 | ||
470 | if (ap->ops->qc_issue) { | |
471 | struct ata_taskfile tf; | |
472 | unsigned int err; | |
473 | ||
474 | ata_tf_init(atadev, &tf); | |
475 | ||
476 | /* convert gtf to tf */ | |
477 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */ | |
478 | tf.protocol = atadev->class == ATA_DEV_ATAPI ? | |
479 | ATA_PROT_ATAPI_NODATA : ATA_PROT_NODATA; | |
480 | tf.feature = gtf->tfa[0]; /* 0x1f1 */ | |
481 | tf.nsect = gtf->tfa[1]; /* 0x1f2 */ | |
482 | tf.lbal = gtf->tfa[2]; /* 0x1f3 */ | |
483 | tf.lbam = gtf->tfa[3]; /* 0x1f4 */ | |
484 | tf.lbah = gtf->tfa[4]; /* 0x1f5 */ | |
485 | tf.device = gtf->tfa[5]; /* 0x1f6 */ | |
486 | tf.command = gtf->tfa[6]; /* 0x1f7 */ | |
487 | ||
488 | err = ata_exec_internal(atadev, &tf, NULL, DMA_NONE, NULL, 0); | |
489 | if (err && ata_msg_probe(ap)) | |
490 | ata_dev_printk(atadev, KERN_ERR, | |
491 | "%s: ata_exec_internal failed: %u\n", | |
492 | __FUNCTION__, err); | |
493 | } else | |
494 | if (ata_msg_warn(ap)) | |
495 | ata_dev_printk(atadev, KERN_WARNING, | |
496 | "%s: SATA driver is missing qc_issue function" | |
497 | " entry points\n", | |
498 | __FUNCTION__); | |
499 | } | |
500 | ||
501 | /** | |
502 | * do_drive_set_taskfiles - write the drive taskfile settings from _GTF | |
503 | * @ap: the ata_port for the drive | |
504 | * @atadev: target ata_device | |
505 | * @gtf_length: total number of bytes of _GTF taskfiles | |
506 | * @gtf_address: location of _GTF taskfile arrays | |
507 | * | |
508 | * This applies to both PATA and SATA drives. | |
509 | * | |
510 | * Write {gtf_address, length gtf_length} in groups of | |
511 | * REGS_PER_GTF bytes. | |
512 | */ | |
513 | static int do_drive_set_taskfiles(struct ata_port *ap, | |
514 | struct ata_device *atadev, unsigned int gtf_length, | |
515 | unsigned long gtf_address) | |
516 | { | |
517 | int err = -ENODEV; | |
518 | int gtf_count = gtf_length / REGS_PER_GTF; | |
519 | int ix; | |
520 | struct taskfile_array *gtf; | |
521 | ||
522 | if (ata_msg_probe(ap)) | |
878d4fed TH |
523 | ata_dev_printk(atadev, KERN_DEBUG, "%s: ENTER: port#: %d\n", |
524 | __FUNCTION__, ap->port_no); | |
11ef697b KCA |
525 | |
526 | if (noacpi || !(ap->cbl == ATA_CBL_SATA)) | |
527 | return 0; | |
528 | ||
529 | if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED)) | |
530 | goto out; | |
531 | if (!gtf_count) /* shouldn't be here */ | |
532 | goto out; | |
533 | ||
534 | if (gtf_length % REGS_PER_GTF) { | |
535 | if (ata_msg_drv(ap)) | |
536 | ata_dev_printk(atadev, KERN_ERR, | |
537 | "%s: unexpected GTF length (%d)\n", | |
538 | __FUNCTION__, gtf_length); | |
539 | goto out; | |
540 | } | |
541 | ||
542 | for (ix = 0; ix < gtf_count; ix++) { | |
543 | gtf = (struct taskfile_array *) | |
544 | (gtf_address + ix * REGS_PER_GTF); | |
545 | ||
546 | /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */ | |
547 | taskfile_load_raw(ap, atadev, gtf); | |
548 | } | |
549 | ||
550 | err = 0; | |
551 | out: | |
552 | return err; | |
553 | } | |
554 | ||
555 | /** | |
556 | * ata_acpi_exec_tfs - get then write drive taskfile settings | |
557 | * @ap: the ata_port for the drive | |
558 | * | |
559 | * This applies to both PATA and SATA drives. | |
560 | */ | |
561 | int ata_acpi_exec_tfs(struct ata_port *ap) | |
562 | { | |
563 | int ix; | |
564 | int ret =0; | |
565 | unsigned int gtf_length; | |
566 | unsigned long gtf_address; | |
567 | unsigned long obj_loc; | |
568 | ||
569 | if (noacpi) | |
570 | return 0; | |
571 | ||
572 | for (ix = 0; ix < ATA_MAX_DEVICES; ix++) { | |
573 | if (!ata_dev_enabled(&ap->device[ix])) | |
574 | continue; | |
575 | ||
576 | ret = do_drive_get_GTF(ap, ix, | |
577 | >f_length, >f_address, &obj_loc); | |
578 | if (ret < 0) { | |
579 | if (ata_msg_probe(ap)) | |
580 | ata_port_printk(ap, KERN_DEBUG, | |
581 | "%s: get_GTF error (%d)\n", | |
582 | __FUNCTION__, ret); | |
583 | break; | |
584 | } | |
585 | ||
586 | ret = do_drive_set_taskfiles(ap, &ap->device[ix], | |
587 | gtf_length, gtf_address); | |
588 | kfree((void *)obj_loc); | |
589 | if (ret < 0) { | |
590 | if (ata_msg_probe(ap)) | |
591 | ata_port_printk(ap, KERN_DEBUG, | |
592 | "%s: set_taskfiles error (%d)\n", | |
593 | __FUNCTION__, ret); | |
594 | break; | |
595 | } | |
596 | } | |
597 | ||
598 | return ret; | |
599 | } | |
600 | ||
7ea1fbc2 KCA |
601 | /** |
602 | * ata_acpi_push_id - send Identify data to drive | |
603 | * @ap: the ata_port for the drive | |
604 | * @ix: drive index | |
605 | * | |
606 | * _SDD ACPI object: for SATA mode only | |
607 | * Must be after Identify (Packet) Device -- uses its data | |
608 | * ATM this function never returns a failure. It is an optional | |
609 | * method and if it fails for whatever reason, we should still | |
610 | * just keep going. | |
611 | */ | |
612 | int ata_acpi_push_id(struct ata_port *ap, unsigned int ix) | |
613 | { | |
614 | acpi_handle handle; | |
615 | acpi_integer pcidevfn; | |
616 | int err; | |
617 | struct device *dev = ap->host->dev; | |
618 | struct ata_device *atadev = &ap->device[ix]; | |
619 | u32 dev_adr; | |
620 | acpi_status status; | |
621 | struct acpi_object_list input; | |
622 | union acpi_object in_params[1]; | |
623 | ||
624 | if (noacpi) | |
625 | return 0; | |
626 | ||
627 | if (ata_msg_probe(ap)) | |
878d4fed TH |
628 | ata_dev_printk(atadev, KERN_DEBUG, "%s: ix = %d, port#: %d\n", |
629 | __FUNCTION__, ix, ap->port_no); | |
7ea1fbc2 KCA |
630 | |
631 | /* Don't continue if not a SATA device. */ | |
632 | if (!(ap->cbl == ATA_CBL_SATA)) { | |
633 | if (ata_msg_probe(ap)) | |
634 | ata_dev_printk(atadev, KERN_DEBUG, | |
635 | "%s: Not a SATA device\n", __FUNCTION__); | |
636 | goto out; | |
637 | } | |
638 | ||
639 | /* Don't continue if device has no _ADR method. | |
640 | * _SDD is intended for known motherboard devices. */ | |
641 | err = sata_get_dev_handle(dev, &handle, &pcidevfn); | |
642 | if (err < 0) { | |
643 | if (ata_msg_probe(ap)) | |
644 | ata_dev_printk(atadev, KERN_DEBUG, | |
645 | "%s: sata_get_dev_handle failed (%d\n", | |
646 | __FUNCTION__, err); | |
647 | goto out; | |
648 | } | |
649 | ||
650 | /* Get this drive's _ADR info, if not already known */ | |
651 | if (!atadev->obj_handle) { | |
652 | dev_adr = SATA_ADR_RSVD; | |
653 | err = get_sata_adr(dev, handle, pcidevfn, ix, ap, atadev, | |
654 | &dev_adr); | |
655 | if (err < 0 || dev_adr == SATA_ADR_RSVD || | |
656 | !atadev->obj_handle) { | |
657 | if (ata_msg_probe(ap)) | |
658 | ata_dev_printk(atadev, KERN_DEBUG, | |
659 | "%s: get_sata_adr failed: " | |
660 | "err=%d, dev_adr=%u, obj_handle=0x%p\n", | |
661 | __FUNCTION__, err, dev_adr, | |
662 | atadev->obj_handle); | |
663 | goto out; | |
664 | } | |
665 | } | |
666 | ||
667 | /* Give the drive Identify data to the drive via the _SDD method */ | |
668 | /* _SDD: set up input parameters */ | |
669 | input.count = 1; | |
670 | input.pointer = in_params; | |
671 | in_params[0].type = ACPI_TYPE_BUFFER; | |
9de1cc9c | 672 | in_params[0].buffer.length = sizeof(atadev->id[0]) * ATA_ID_WORDS; |
7ea1fbc2 KCA |
673 | in_params[0].buffer.pointer = (u8 *)atadev->id; |
674 | /* Output buffer: _SDD has no output */ | |
675 | ||
676 | /* It's OK for _SDD to be missing too. */ | |
677 | swap_buf_le16(atadev->id, ATA_ID_WORDS); | |
678 | status = acpi_evaluate_object(atadev->obj_handle, "_SDD", &input, NULL); | |
679 | swap_buf_le16(atadev->id, ATA_ID_WORDS); | |
680 | ||
681 | err = ACPI_FAILURE(status) ? -EIO : 0; | |
682 | if (err < 0) { | |
683 | if (ata_msg_probe(ap)) | |
684 | ata_dev_printk(atadev, KERN_DEBUG, | |
878d4fed TH |
685 | "%s _SDD error: status = 0x%x\n", |
686 | __FUNCTION__, status); | |
7ea1fbc2 KCA |
687 | } |
688 | ||
689 | /* always return success */ | |
690 | out: | |
691 | return 0; | |
692 | } | |
693 | ||
694 |