aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/libata-acpi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ata/libata-acpi.c')
-rw-r--r--drivers/ata/libata-acpi.c69
1 files changed, 49 insertions, 20 deletions
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index b3aeca368774..e0dd132fd490 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -41,6 +41,12 @@ static int is_pci_dev(struct device *dev)
41 return (dev->bus == &pci_bus_type); 41 return (dev->bus == &pci_bus_type);
42} 42}
43 43
44static void ata_acpi_clear_gtf(struct ata_device *dev)
45{
46 kfree(dev->gtf_cache);
47 dev->gtf_cache = NULL;
48}
49
44/** 50/**
45 * ata_acpi_associate_sata_port - associate SATA port with ACPI objects 51 * ata_acpi_associate_sata_port - associate SATA port with ACPI objects
46 * @ap: target SATA port 52 * @ap: target SATA port
@@ -327,7 +333,6 @@ EXPORT_SYMBOL_GPL(ata_acpi_stm);
327 * ata_dev_get_GTF - get the drive bootup default taskfile settings 333 * ata_dev_get_GTF - get the drive bootup default taskfile settings
328 * @dev: target ATA device 334 * @dev: target ATA device
329 * @gtf: output parameter for buffer containing _GTF taskfile arrays 335 * @gtf: output parameter for buffer containing _GTF taskfile arrays
330 * @ptr_to_free: pointer which should be freed
331 * 336 *
332 * This applies to both PATA and SATA drives. 337 * This applies to both PATA and SATA drives.
333 * 338 *
@@ -344,8 +349,7 @@ EXPORT_SYMBOL_GPL(ata_acpi_stm);
344 * Number of taskfiles on success, 0 if _GTF doesn't exist or doesn't 349 * Number of taskfiles on success, 0 if _GTF doesn't exist or doesn't
345 * contain valid data. 350 * contain valid data.
346 */ 351 */
347static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf, 352static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf)
348 void **ptr_to_free)
349{ 353{
350 struct ata_port *ap = dev->link->ap; 354 struct ata_port *ap = dev->link->ap;
351 acpi_status status; 355 acpi_status status;
@@ -353,6 +357,12 @@ static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf,
353 union acpi_object *out_obj; 357 union acpi_object *out_obj;
354 int rc = 0; 358 int rc = 0;
355 359
360 /* if _GTF is cached, use the cached value */
361 if (dev->gtf_cache) {
362 out_obj = dev->gtf_cache;
363 goto done;
364 }
365
356 /* set up output buffer */ 366 /* set up output buffer */
357 output.length = ACPI_ALLOCATE_BUFFER; 367 output.length = ACPI_ALLOCATE_BUFFER;
358 output.pointer = NULL; /* ACPI-CA sets this; save/free it later */ 368 output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
@@ -363,6 +373,7 @@ static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf,
363 373
364 /* _GTF has no input parameters */ 374 /* _GTF has no input parameters */
365 status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output); 375 status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output);
376 out_obj = dev->gtf_cache = output.pointer;
366 377
367 if (ACPI_FAILURE(status)) { 378 if (ACPI_FAILURE(status)) {
368 if (status != AE_NOT_FOUND) { 379 if (status != AE_NOT_FOUND) {
@@ -383,7 +394,6 @@ static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf,
383 goto out_free; 394 goto out_free;
384 } 395 }
385 396
386 out_obj = output.pointer;
387 if (out_obj->type != ACPI_TYPE_BUFFER) { 397 if (out_obj->type != ACPI_TYPE_BUFFER) {
388 ata_dev_printk(dev, KERN_WARNING, 398 ata_dev_printk(dev, KERN_WARNING,
389 "_GTF unexpected object type 0x%x\n", 399 "_GTF unexpected object type 0x%x\n",
@@ -398,18 +408,19 @@ static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf,
398 goto out_free; 408 goto out_free;
399 } 409 }
400 410
401 *ptr_to_free = out_obj; 411 done:
402 *gtf = (void *)out_obj->buffer.pointer;
403 rc = out_obj->buffer.length / REGS_PER_GTF; 412 rc = out_obj->buffer.length / REGS_PER_GTF;
404 413 if (gtf) {
405 if (ata_msg_probe(ap)) 414 *gtf = (void *)out_obj->buffer.pointer;
406 ata_dev_printk(dev, KERN_DEBUG, "%s: returning " 415 if (ata_msg_probe(ap))
407 "gtf=%p, gtf_count=%d, ptr_to_free=%p\n", 416 ata_dev_printk(dev, KERN_DEBUG,
408 __FUNCTION__, *gtf, rc, *ptr_to_free); 417 "%s: returning gtf=%p, gtf_count=%d\n",
418 __FUNCTION__, *gtf, rc);
419 }
409 return rc; 420 return rc;
410 421
411 out_free: 422 out_free:
412 kfree(output.pointer); 423 ata_acpi_clear_gtf(dev);
413 return rc; 424 return rc;
414} 425}
415 426
@@ -533,11 +544,10 @@ static int taskfile_load_raw(struct ata_device *dev,
533static int ata_acpi_exec_tfs(struct ata_device *dev) 544static int ata_acpi_exec_tfs(struct ata_device *dev)
534{ 545{
535 struct ata_acpi_gtf *gtf = NULL; 546 struct ata_acpi_gtf *gtf = NULL;
536 void *ptr_to_free = NULL;
537 int gtf_count, i, rc; 547 int gtf_count, i, rc;
538 548
539 /* get taskfiles */ 549 /* get taskfiles */
540 gtf_count = ata_dev_get_GTF(dev, &gtf, &ptr_to_free); 550 gtf_count = ata_dev_get_GTF(dev, &gtf);
541 551
542 /* execute them */ 552 /* execute them */
543 for (i = 0, rc = 0; i < gtf_count; i++) { 553 for (i = 0, rc = 0; i < gtf_count; i++) {
@@ -551,7 +561,7 @@ static int ata_acpi_exec_tfs(struct ata_device *dev)
551 rc = tmp; 561 rc = tmp;
552 } 562 }
553 563
554 kfree(ptr_to_free); 564 ata_acpi_clear_gtf(dev);
555 565
556 if (rc == 0) 566 if (rc == 0)
557 return gtf_count; 567 return gtf_count;
@@ -644,13 +654,31 @@ void ata_acpi_on_resume(struct ata_port *ap)
644 const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); 654 const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap);
645 struct ata_device *dev; 655 struct ata_device *dev;
646 656
647 /* restore timing parameters */ 657 if (ap->acpi_handle && gtm) {
648 if (ap->acpi_handle && gtm) 658 /* _GTM valid */
659
660 /* restore timing parameters */
649 ata_acpi_stm(ap, gtm); 661 ata_acpi_stm(ap, gtm);
650 662
651 /* schedule _GTF */ 663 /* _GTF should immediately follow _STM so that it can
652 ata_link_for_each_dev(dev, &ap->link) 664 * use values set by _STM. Cache _GTF result and
653 dev->flags |= ATA_DFLAG_ACPI_PENDING; 665 * schedule _GTF.
666 */
667 ata_link_for_each_dev(dev, &ap->link) {
668 ata_acpi_clear_gtf(dev);
669 if (ata_dev_get_GTF(dev, NULL) >= 0)
670 dev->flags |= ATA_DFLAG_ACPI_PENDING;
671 }
672 } else {
673 /* SATA _GTF needs to be evaulated after _SDD and
674 * there's no reason to evaluate IDE _GTF early
675 * without _STM. Clear cache and schedule _GTF.
676 */
677 ata_link_for_each_dev(dev, &ap->link) {
678 ata_acpi_clear_gtf(dev);
679 dev->flags |= ATA_DFLAG_ACPI_PENDING;
680 }
681 }
654} 682}
655 683
656/** 684/**
@@ -735,4 +763,5 @@ int ata_acpi_on_devcfg(struct ata_device *dev)
735 */ 763 */
736void ata_acpi_on_disable(struct ata_device *dev) 764void ata_acpi_on_disable(struct ata_device *dev)
737{ 765{
766 ata_acpi_clear_gtf(dev);
738} 767}