Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 2 | /* |
| 3 | * libata-acpi.c |
| 4 | * Provides ACPI support for PATA/SATA. |
| 5 | * |
| 6 | * Copyright (C) 2006 Intel Corp. |
| 7 | * Copyright (C) 2006 Randy Dunlap |
| 8 | */ |
| 9 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 10 | #include <linux/module.h> |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 11 | #include <linux/ata.h> |
| 12 | #include <linux/delay.h> |
| 13 | #include <linux/device.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/acpi.h> |
| 17 | #include <linux/libata.h> |
| 18 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Lin Ming | 3bd46600a7 | 2012-06-25 16:13:06 +0800 | [diff] [blame] | 20 | #include <linux/pm_runtime.h> |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 21 | #include <scsi/scsi_device.h> |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 22 | #include "libata.h" |
| 23 | |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 24 | unsigned int ata_acpi_gtf_filter = ATA_ACPI_FILTER_DEFAULT; |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 25 | module_param_named(acpi_gtf_filter, ata_acpi_gtf_filter, int, 0644); |
Tejun Heo | fa5b561 | 2009-09-16 04:17:02 +0900 | [diff] [blame] | 26 | MODULE_PARM_DESC(acpi_gtf_filter, "filter mask for ACPI _GTF commands, set to filter out (0x1=set xfermode, 0x2=lock/freeze lock, 0x4=DIPM, 0x8=FPDMA non-zero offset, 0x10=FPDMA DMA Setup FIS auto-activate)"); |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 27 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 28 | #define NO_PORT_MULT 0xffff |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 29 | #define SATA_ADR(root, pmp) (((root) << 16) | (pmp)) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 30 | |
| 31 | #define REGS_PER_GTF 7 |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 32 | struct ata_acpi_gtf { |
| 33 | u8 tf[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */ |
| 34 | } __packed; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 35 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 36 | static void ata_acpi_clear_gtf(struct ata_device *dev) |
| 37 | { |
| 38 | kfree(dev->gtf_cache); |
| 39 | dev->gtf_cache = NULL; |
| 40 | } |
| 41 | |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 42 | struct ata_acpi_hotplug_context { |
| 43 | struct acpi_hotplug_context hp; |
| 44 | union { |
| 45 | struct ata_port *ap; |
| 46 | struct ata_device *dev; |
| 47 | } data; |
| 48 | }; |
| 49 | |
| 50 | #define ata_hotplug_data(context) (container_of((context), struct ata_acpi_hotplug_context, hp)->data) |
| 51 | |
Matthew Garrett | 30dcf76 | 2012-06-25 16:13:04 +0800 | [diff] [blame] | 52 | /** |
Matthew Garrett | 30dcf76 | 2012-06-25 16:13:04 +0800 | [diff] [blame] | 53 | * ata_dev_acpi_handle - provide the acpi_handle for an ata_device |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 54 | * @dev: the acpi_handle returned will correspond to this device |
Matthew Garrett | 30dcf76 | 2012-06-25 16:13:04 +0800 | [diff] [blame] | 55 | * |
| 56 | * Returns the acpi_handle for the ACPI namespace object corresponding to |
| 57 | * the ata_device passed into the function, or NULL if no such object exists |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 58 | * or ACPI is disabled for this device due to consecutive errors. |
Matthew Garrett | 30dcf76 | 2012-06-25 16:13:04 +0800 | [diff] [blame] | 59 | */ |
| 60 | acpi_handle ata_dev_acpi_handle(struct ata_device *dev) |
Matthew Garrett | 6b66d95 | 2012-06-25 16:13:03 +0800 | [diff] [blame] | 61 | { |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 62 | return dev->flags & ATA_DFLAG_ACPI_DISABLED ? |
| 63 | NULL : ACPI_HANDLE(&dev->tdev); |
Matthew Garrett | 6b66d95 | 2012-06-25 16:13:03 +0800 | [diff] [blame] | 64 | } |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 65 | |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 66 | /* @ap and @dev are the same as ata_acpi_handle_hotplug() */ |
| 67 | static void ata_acpi_detach_device(struct ata_port *ap, struct ata_device *dev) |
| 68 | { |
| 69 | if (dev) |
| 70 | dev->flags |= ATA_DFLAG_DETACH; |
| 71 | else { |
| 72 | struct ata_link *tlink; |
| 73 | struct ata_device *tdev; |
| 74 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 75 | ata_for_each_link(tlink, ap, EDGE) |
| 76 | ata_for_each_dev(tdev, tlink, ALL) |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 77 | tdev->flags |= ATA_DFLAG_DETACH; |
| 78 | } |
| 79 | |
| 80 | ata_port_schedule_eh(ap); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * ata_acpi_handle_hotplug - ACPI event handler backend |
| 85 | * @ap: ATA port ACPI event occurred |
| 86 | * @dev: ATA device ACPI event occurred (can be NULL) |
| 87 | * @event: ACPI event which occurred |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 88 | * |
| 89 | * All ACPI bay / device realted events end up in this function. If |
| 90 | * the event is port-wide @dev is NULL. If the event is specific to a |
| 91 | * device, @dev points to it. |
| 92 | * |
| 93 | * Hotplug (as opposed to unplug) notification is always handled as |
| 94 | * port-wide while unplug only kills the target device on device-wide |
| 95 | * event. |
| 96 | * |
| 97 | * LOCKING: |
| 98 | * ACPI notify handler context. May sleep. |
| 99 | */ |
| 100 | static void ata_acpi_handle_hotplug(struct ata_port *ap, struct ata_device *dev, |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 101 | u32 event) |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 102 | { |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 103 | struct ata_eh_info *ehi = &ap->link.eh_info; |
Tejun Heo | 233f112 | 2008-03-12 14:24:43 +0900 | [diff] [blame] | 104 | int wait = 0; |
| 105 | unsigned long flags; |
Zhang Rui | 3c1e389 | 2008-07-11 09:42:03 -0400 | [diff] [blame] | 106 | |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 107 | spin_lock_irqsave(ap->lock, flags); |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 108 | /* |
| 109 | * When dock driver calls into the routine, it will always use |
| 110 | * ACPI_NOTIFY_BUS_CHECK/ACPI_NOTIFY_DEVICE_CHECK for add and |
| 111 | * ACPI_NOTIFY_EJECT_REQUEST for remove |
| 112 | */ |
Tejun Heo | 233f112 | 2008-03-12 14:24:43 +0900 | [diff] [blame] | 113 | switch (event) { |
| 114 | case ACPI_NOTIFY_BUS_CHECK: |
| 115 | case ACPI_NOTIFY_DEVICE_CHECK: |
| 116 | ata_ehi_push_desc(ehi, "ACPI event"); |
Jeff Garzik | c85665f | 2008-05-19 17:56:10 -0400 | [diff] [blame] | 117 | |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 118 | ata_ehi_hotplugged(ehi); |
| 119 | ata_port_freeze(ap); |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 120 | break; |
| 121 | case ACPI_NOTIFY_EJECT_REQUEST: |
| 122 | ata_ehi_push_desc(ehi, "ACPI event"); |
| 123 | |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 124 | ata_acpi_detach_device(ap, dev); |
| 125 | wait = 1; |
| 126 | break; |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Matthew Garrett | ae6c23c | 2008-05-19 17:29:34 +0100 | [diff] [blame] | 129 | spin_unlock_irqrestore(ap->lock, flags); |
| 130 | |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 131 | if (wait) |
Matthew Garrett | ae6c23c | 2008-05-19 17:29:34 +0100 | [diff] [blame] | 132 | ata_port_wait_eh(ap); |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 135 | static int ata_acpi_dev_notify_dock(struct acpi_device *adev, u32 event) |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 136 | { |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 137 | struct ata_device *dev = ata_hotplug_data(adev->hp).dev; |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 138 | ata_acpi_handle_hotplug(dev->link->ap, dev, event); |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 139 | return 0; |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 140 | } |
| 141 | |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 142 | static int ata_acpi_ap_notify_dock(struct acpi_device *adev, u32 event) |
Holger Macht | 664d080 | 2008-06-03 20:27:59 +0200 | [diff] [blame] | 143 | { |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 144 | ata_acpi_handle_hotplug(ata_hotplug_data(adev->hp).ap, NULL, event); |
| 145 | return 0; |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 148 | static void ata_acpi_uevent(struct ata_port *ap, struct ata_device *dev, |
| 149 | u32 event) |
| 150 | { |
| 151 | struct kobject *kobj = NULL; |
| 152 | char event_string[20]; |
| 153 | char *envp[] = { event_string, NULL }; |
| 154 | |
| 155 | if (dev) { |
| 156 | if (dev->sdev) |
| 157 | kobj = &dev->sdev->sdev_gendev.kobj; |
| 158 | } else |
| 159 | kobj = &ap->dev->kobj; |
| 160 | |
| 161 | if (kobj) { |
| 162 | snprintf(event_string, 20, "BAY_EVENT=%d", event); |
| 163 | kobject_uevent_env(kobj, KOBJ_CHANGE, envp); |
| 164 | } |
| 165 | } |
| 166 | |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 167 | static void ata_acpi_ap_uevent(struct acpi_device *adev, u32 event) |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 168 | { |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 169 | ata_acpi_uevent(ata_hotplug_data(adev->hp).ap, NULL, event); |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 170 | } |
| 171 | |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 172 | static void ata_acpi_dev_uevent(struct acpi_device *adev, u32 event) |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 173 | { |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 174 | struct ata_device *dev = ata_hotplug_data(adev->hp).dev; |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 175 | ata_acpi_uevent(dev->link->ap, dev, event); |
| 176 | } |
| 177 | |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 178 | /* bind acpi handle to pata port */ |
| 179 | void ata_acpi_bind_port(struct ata_port *ap) |
Aaron Lu | 4452152 | 2013-06-20 09:38:34 +0800 | [diff] [blame] | 180 | { |
Rafael J. Wysocki | 9c5ad36 | 2013-11-28 23:58:28 +0100 | [diff] [blame] | 181 | struct acpi_device *host_companion = ACPI_COMPANION(ap->host->dev); |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 182 | struct acpi_device *adev; |
| 183 | struct ata_acpi_hotplug_context *context; |
Aaron Lu | 4452152 | 2013-06-20 09:38:34 +0800 | [diff] [blame] | 184 | |
Rafael J. Wysocki | 9c5ad36 | 2013-11-28 23:58:28 +0100 | [diff] [blame] | 185 | if (libata_noacpi || ap->flags & ATA_FLAG_ACPI_SATA || !host_companion) |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 186 | return; |
Aaron Lu | 4452152 | 2013-06-20 09:38:34 +0800 | [diff] [blame] | 187 | |
Rafael J. Wysocki | 9c5ad36 | 2013-11-28 23:58:28 +0100 | [diff] [blame] | 188 | acpi_preset_companion(&ap->tdev, host_companion, ap->port_no); |
Aaron Lu | 4452152 | 2013-06-20 09:38:34 +0800 | [diff] [blame] | 189 | |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 190 | if (ata_acpi_gtm(ap, &ap->__acpi_init_gtm) == 0) |
| 191 | ap->pflags |= ATA_PFLAG_INIT_GTM_VALID; |
Aaron Lu | 4452152 | 2013-06-20 09:38:34 +0800 | [diff] [blame] | 192 | |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 193 | adev = ACPI_COMPANION(&ap->tdev); |
| 194 | if (!adev || adev->hp) |
| 195 | return; |
| 196 | |
| 197 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 198 | if (!context) |
| 199 | return; |
| 200 | |
| 201 | context->data.ap = ap; |
| 202 | acpi_initialize_hp_context(adev, &context->hp, ata_acpi_ap_notify_dock, |
| 203 | ata_acpi_ap_uevent); |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 204 | } |
Aaron Lu | 4452152 | 2013-06-20 09:38:34 +0800 | [diff] [blame] | 205 | |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 206 | void ata_acpi_bind_dev(struct ata_device *dev) |
| 207 | { |
| 208 | struct ata_port *ap = dev->link->ap; |
Rafael J. Wysocki | 9c5ad36 | 2013-11-28 23:58:28 +0100 | [diff] [blame] | 209 | struct acpi_device *port_companion = ACPI_COMPANION(&ap->tdev); |
| 210 | struct acpi_device *host_companion = ACPI_COMPANION(ap->host->dev); |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 211 | struct acpi_device *parent, *adev; |
| 212 | struct ata_acpi_hotplug_context *context; |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 213 | u64 adr; |
| 214 | |
| 215 | /* |
Rafael J. Wysocki | 9c5ad36 | 2013-11-28 23:58:28 +0100 | [diff] [blame] | 216 | * For both sata/pata devices, host companion device is required. |
| 217 | * For pata device, port companion device is also required. |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 218 | */ |
Rafael J. Wysocki | 9c5ad36 | 2013-11-28 23:58:28 +0100 | [diff] [blame] | 219 | if (libata_noacpi || !host_companion || |
| 220 | (!(ap->flags & ATA_FLAG_ACPI_SATA) && !port_companion)) |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 221 | return; |
| 222 | |
| 223 | if (ap->flags & ATA_FLAG_ACPI_SATA) { |
| 224 | if (!sata_pmp_attached(ap)) |
| 225 | adr = SATA_ADR(ap->port_no, NO_PORT_MULT); |
| 226 | else |
| 227 | adr = SATA_ADR(ap->port_no, dev->link->pmp); |
Rafael J. Wysocki | 9c5ad36 | 2013-11-28 23:58:28 +0100 | [diff] [blame] | 228 | parent = host_companion; |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 229 | } else { |
| 230 | adr = dev->devno; |
Rafael J. Wysocki | 9c5ad36 | 2013-11-28 23:58:28 +0100 | [diff] [blame] | 231 | parent = port_companion; |
Aaron Lu | 4452152 | 2013-06-20 09:38:34 +0800 | [diff] [blame] | 232 | } |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 233 | |
Rafael J. Wysocki | 9c5ad36 | 2013-11-28 23:58:28 +0100 | [diff] [blame] | 234 | acpi_preset_companion(&dev->tdev, parent, adr); |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 235 | adev = ACPI_COMPANION(&dev->tdev); |
| 236 | if (!adev || adev->hp) |
| 237 | return; |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 238 | |
Rafael J. Wysocki | 5d51320 | 2014-02-22 00:48:31 +0100 | [diff] [blame] | 239 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 240 | if (!context) |
| 241 | return; |
| 242 | |
| 243 | context->data.dev = dev; |
| 244 | acpi_initialize_hp_context(adev, &context->hp, ata_acpi_dev_notify_dock, |
| 245 | ata_acpi_dev_uevent); |
Aaron Lu | 4452152 | 2013-06-20 09:38:34 +0800 | [diff] [blame] | 246 | } |
| 247 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 248 | /** |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 249 | * ata_acpi_dissociate - dissociate ATA host from ACPI objects |
| 250 | * @host: target ATA host |
| 251 | * |
| 252 | * This function is called during driver detach after the whole host |
| 253 | * is shut down. |
| 254 | * |
| 255 | * LOCKING: |
| 256 | * EH context. |
| 257 | */ |
| 258 | void ata_acpi_dissociate(struct ata_host *host) |
| 259 | { |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 260 | int i; |
| 261 | |
| 262 | /* Restore initial _GTM values so that driver which attaches |
| 263 | * afterward can use them too. |
| 264 | */ |
| 265 | for (i = 0; i < host->n_ports; i++) { |
| 266 | struct ata_port *ap = host->ports[i]; |
| 267 | const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); |
| 268 | |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 269 | if (ACPI_HANDLE(&ap->tdev) && gtm) |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 270 | ata_acpi_stm(ap, gtm); |
| 271 | } |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 272 | } |
| 273 | |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 274 | /** |
| 275 | * ata_acpi_gtm - execute _GTM |
| 276 | * @ap: target ATA port |
| 277 | * @gtm: out parameter for _GTM result |
| 278 | * |
| 279 | * Evaluate _GTM and store the result in @gtm. |
| 280 | * |
| 281 | * LOCKING: |
| 282 | * EH context. |
| 283 | * |
| 284 | * RETURNS: |
| 285 | * 0 on success, -ENOENT if _GTM doesn't exist, -errno on failure. |
| 286 | */ |
| 287 | int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *gtm) |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 288 | { |
| 289 | struct acpi_buffer output = { .length = ACPI_ALLOCATE_BUFFER }; |
| 290 | union acpi_object *out_obj; |
| 291 | acpi_status status; |
| 292 | int rc = 0; |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 293 | acpi_handle handle = ACPI_HANDLE(&ap->tdev); |
| 294 | |
| 295 | if (!handle) |
| 296 | return -EINVAL; |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 297 | |
Aaron Lu | d66af4d | 2013-04-27 09:33:07 +0800 | [diff] [blame] | 298 | status = acpi_evaluate_object(handle, "_GTM", NULL, &output); |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 299 | |
| 300 | rc = -ENOENT; |
| 301 | if (status == AE_NOT_FOUND) |
| 302 | goto out_free; |
| 303 | |
| 304 | rc = -EINVAL; |
| 305 | if (ACPI_FAILURE(status)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 306 | ata_port_err(ap, "ACPI get timing mode failed (AE 0x%x)\n", |
| 307 | status); |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 308 | goto out_free; |
| 309 | } |
| 310 | |
| 311 | out_obj = output.pointer; |
| 312 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 313 | ata_port_warn(ap, "_GTM returned unexpected object type 0x%x\n", |
| 314 | out_obj->type); |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 315 | |
| 316 | goto out_free; |
| 317 | } |
| 318 | |
| 319 | if (out_obj->buffer.length != sizeof(struct ata_acpi_gtm)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 320 | ata_port_err(ap, "_GTM returned invalid length %d\n", |
| 321 | out_obj->buffer.length); |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 322 | goto out_free; |
| 323 | } |
| 324 | |
| 325 | memcpy(gtm, out_obj->buffer.pointer, sizeof(struct ata_acpi_gtm)); |
| 326 | rc = 0; |
| 327 | out_free: |
| 328 | kfree(output.pointer); |
| 329 | return rc; |
| 330 | } |
| 331 | |
Alan Cox | badff03 | 2007-10-04 21:28:18 +0100 | [diff] [blame] | 332 | EXPORT_SYMBOL_GPL(ata_acpi_gtm); |
| 333 | |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 334 | /** |
| 335 | * ata_acpi_stm - execute _STM |
| 336 | * @ap: target ATA port |
| 337 | * @stm: timing parameter to _STM |
| 338 | * |
| 339 | * Evaluate _STM with timing parameter @stm. |
| 340 | * |
| 341 | * LOCKING: |
| 342 | * EH context. |
| 343 | * |
| 344 | * RETURNS: |
| 345 | * 0 on success, -ENOENT if _STM doesn't exist, -errno on failure. |
| 346 | */ |
Tejun Heo | 0d02f0b | 2007-12-15 15:04:57 +0900 | [diff] [blame] | 347 | int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm) |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 348 | { |
| 349 | acpi_status status; |
Tejun Heo | 0d02f0b | 2007-12-15 15:04:57 +0900 | [diff] [blame] | 350 | struct ata_acpi_gtm stm_buf = *stm; |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 351 | struct acpi_object_list input; |
| 352 | union acpi_object in_params[3]; |
| 353 | |
| 354 | in_params[0].type = ACPI_TYPE_BUFFER; |
| 355 | in_params[0].buffer.length = sizeof(struct ata_acpi_gtm); |
Tejun Heo | 0d02f0b | 2007-12-15 15:04:57 +0900 | [diff] [blame] | 356 | in_params[0].buffer.pointer = (u8 *)&stm_buf; |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 357 | /* Buffers for id may need byteswapping ? */ |
| 358 | in_params[1].type = ACPI_TYPE_BUFFER; |
| 359 | in_params[1].buffer.length = 512; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 360 | in_params[1].buffer.pointer = (u8 *)ap->link.device[0].id; |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 361 | in_params[2].type = ACPI_TYPE_BUFFER; |
| 362 | in_params[2].buffer.length = 512; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 363 | in_params[2].buffer.pointer = (u8 *)ap->link.device[1].id; |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 364 | |
| 365 | input.count = 3; |
| 366 | input.pointer = in_params; |
| 367 | |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 368 | status = acpi_evaluate_object(ACPI_HANDLE(&ap->tdev), "_STM", |
| 369 | &input, NULL); |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 370 | |
| 371 | if (status == AE_NOT_FOUND) |
| 372 | return -ENOENT; |
| 373 | if (ACPI_FAILURE(status)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 374 | ata_port_err(ap, "ACPI set timing mode failed (status=0x%x)\n", |
| 375 | status); |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 376 | return -EINVAL; |
| 377 | } |
| 378 | return 0; |
| 379 | } |
| 380 | |
Alan Cox | badff03 | 2007-10-04 21:28:18 +0100 | [diff] [blame] | 381 | EXPORT_SYMBOL_GPL(ata_acpi_stm); |
| 382 | |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 383 | /** |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 384 | * ata_dev_get_GTF - get the drive bootup default taskfile settings |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 385 | * @dev: target ATA device |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 386 | * @gtf: output parameter for buffer containing _GTF taskfile arrays |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 387 | * |
| 388 | * This applies to both PATA and SATA drives. |
| 389 | * |
| 390 | * The _GTF method has no input parameters. |
| 391 | * It returns a variable number of register set values (registers |
| 392 | * hex 1F1..1F7, taskfiles). |
| 393 | * The <variable number> is not known in advance, so have ACPI-CA |
| 394 | * allocate the buffer as needed and return it, then free it later. |
| 395 | * |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 396 | * LOCKING: |
| 397 | * EH context. |
| 398 | * |
| 399 | * RETURNS: |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 400 | * Number of taskfiles on success, 0 if _GTF doesn't exist. -EINVAL |
| 401 | * if _GTF is invalid. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 402 | */ |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 403 | static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 404 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 405 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 406 | acpi_status status; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 407 | struct acpi_buffer output; |
| 408 | union acpi_object *out_obj; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 409 | int rc = 0; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 410 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 411 | /* if _GTF is cached, use the cached value */ |
| 412 | if (dev->gtf_cache) { |
| 413 | out_obj = dev->gtf_cache; |
| 414 | goto done; |
| 415 | } |
| 416 | |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 417 | /* set up output buffer */ |
| 418 | output.length = ACPI_ALLOCATE_BUFFER; |
| 419 | output.pointer = NULL; /* ACPI-CA sets this; save/free it later */ |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 420 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 421 | if (ata_msg_probe(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 422 | ata_dev_dbg(dev, "%s: ENTER: port#: %d\n", |
| 423 | __func__, ap->port_no); |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 424 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 425 | /* _GTF has no input parameters */ |
Matthew Garrett | 30dcf76 | 2012-06-25 16:13:04 +0800 | [diff] [blame] | 426 | status = acpi_evaluate_object(ata_dev_acpi_handle(dev), "_GTF", NULL, |
| 427 | &output); |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 428 | out_obj = dev->gtf_cache = output.pointer; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 429 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 430 | if (ACPI_FAILURE(status)) { |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 431 | if (status != AE_NOT_FOUND) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 432 | ata_dev_warn(dev, "_GTF evaluation failed (AE 0x%x)\n", |
| 433 | status); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 434 | rc = -EINVAL; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 435 | } |
| 436 | goto out_free; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | if (!output.length || !output.pointer) { |
| 440 | if (ata_msg_probe(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 441 | ata_dev_dbg(dev, "%s: Run _GTF: length or ptr is NULL (0x%llx, 0x%p)\n", |
| 442 | __func__, |
| 443 | (unsigned long long)output.length, |
| 444 | output.pointer); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 445 | rc = -EINVAL; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 446 | goto out_free; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 449 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 450 | ata_dev_warn(dev, "_GTF unexpected object type 0x%x\n", |
| 451 | out_obj->type); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 452 | rc = -EINVAL; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 453 | goto out_free; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 456 | if (out_obj->buffer.length % REGS_PER_GTF) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 457 | ata_dev_warn(dev, "unexpected _GTF length (%d)\n", |
| 458 | out_obj->buffer.length); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 459 | rc = -EINVAL; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 460 | goto out_free; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 463 | done: |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 464 | rc = out_obj->buffer.length / REGS_PER_GTF; |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 465 | if (gtf) { |
| 466 | *gtf = (void *)out_obj->buffer.pointer; |
| 467 | if (ata_msg_probe(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 468 | ata_dev_dbg(dev, "%s: returning gtf=%p, gtf_count=%d\n", |
| 469 | __func__, *gtf, rc); |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 470 | } |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 471 | return rc; |
| 472 | |
| 473 | out_free: |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 474 | ata_acpi_clear_gtf(dev); |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 475 | return rc; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Tejun Heo | 7c77fa4 | 2007-12-18 16:33:03 +0900 | [diff] [blame] | 478 | /** |
| 479 | * ata_acpi_gtm_xfermode - determine xfermode from GTM parameter |
| 480 | * @dev: target device |
| 481 | * @gtm: GTM parameter to use |
| 482 | * |
| 483 | * Determine xfermask for @dev from @gtm. |
| 484 | * |
| 485 | * LOCKING: |
| 486 | * None. |
| 487 | * |
| 488 | * RETURNS: |
| 489 | * Determined xfermask. |
| 490 | */ |
| 491 | unsigned long ata_acpi_gtm_xfermask(struct ata_device *dev, |
| 492 | const struct ata_acpi_gtm *gtm) |
| 493 | { |
Tejun Heo | a0f79b9 | 2007-12-18 16:33:05 +0900 | [diff] [blame] | 494 | unsigned long xfer_mask = 0; |
| 495 | unsigned int type; |
| 496 | int unit; |
| 497 | u8 mode; |
Tejun Heo | 7c77fa4 | 2007-12-18 16:33:03 +0900 | [diff] [blame] | 498 | |
| 499 | /* we always use the 0 slot for crap hardware */ |
| 500 | unit = dev->devno; |
| 501 | if (!(gtm->flags & 0x10)) |
| 502 | unit = 0; |
| 503 | |
Tejun Heo | a0f79b9 | 2007-12-18 16:33:05 +0900 | [diff] [blame] | 504 | /* PIO */ |
| 505 | mode = ata_timing_cycle2mode(ATA_SHIFT_PIO, gtm->drive[unit].pio); |
| 506 | xfer_mask |= ata_xfer_mode2mask(mode); |
Tejun Heo | 7c77fa4 | 2007-12-18 16:33:03 +0900 | [diff] [blame] | 507 | |
| 508 | /* See if we have MWDMA or UDMA data. We don't bother with |
| 509 | * MWDMA if UDMA is available as this means the BIOS set UDMA |
| 510 | * and our error changedown if it works is UDMA to PIO anyway. |
| 511 | */ |
Tejun Heo | a0f79b9 | 2007-12-18 16:33:05 +0900 | [diff] [blame] | 512 | if (!(gtm->flags & (1 << (2 * unit)))) |
| 513 | type = ATA_SHIFT_MWDMA; |
| 514 | else |
| 515 | type = ATA_SHIFT_UDMA; |
Tejun Heo | 7c77fa4 | 2007-12-18 16:33:03 +0900 | [diff] [blame] | 516 | |
Tejun Heo | a0f79b9 | 2007-12-18 16:33:05 +0900 | [diff] [blame] | 517 | mode = ata_timing_cycle2mode(type, gtm->drive[unit].dma); |
| 518 | xfer_mask |= ata_xfer_mode2mask(mode); |
| 519 | |
| 520 | return xfer_mask; |
Tejun Heo | 7c77fa4 | 2007-12-18 16:33:03 +0900 | [diff] [blame] | 521 | } |
| 522 | EXPORT_SYMBOL_GPL(ata_acpi_gtm_xfermask); |
| 523 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 524 | /** |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 525 | * ata_acpi_cbl_80wire - Check for 80 wire cable |
| 526 | * @ap: Port to check |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 527 | * @gtm: GTM data to use |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 528 | * |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 529 | * Return 1 if the @gtm indicates the BIOS selected an 80wire mode. |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 530 | */ |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 531 | int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm) |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 532 | { |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 533 | struct ata_device *dev; |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 534 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 535 | ata_for_each_dev(dev, &ap->link, ENABLED) { |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 536 | unsigned long xfer_mask, udma_mask; |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 537 | |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 538 | xfer_mask = ata_acpi_gtm_xfermask(dev, gtm); |
| 539 | ata_unpack_xfermask(xfer_mask, NULL, NULL, &udma_mask); |
| 540 | |
| 541 | if (udma_mask & ~ATA_UDMA_MASK_40C) |
| 542 | return 1; |
| 543 | } |
| 544 | |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 545 | return 0; |
| 546 | } |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 547 | EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire); |
| 548 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 549 | static void ata_acpi_gtf_to_tf(struct ata_device *dev, |
| 550 | const struct ata_acpi_gtf *gtf, |
| 551 | struct ata_taskfile *tf) |
| 552 | { |
| 553 | ata_tf_init(dev, tf); |
| 554 | |
| 555 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 556 | tf->protocol = ATA_PROT_NODATA; |
| 557 | tf->feature = gtf->tf[0]; /* 0x1f1 */ |
| 558 | tf->nsect = gtf->tf[1]; /* 0x1f2 */ |
| 559 | tf->lbal = gtf->tf[2]; /* 0x1f3 */ |
| 560 | tf->lbam = gtf->tf[3]; /* 0x1f4 */ |
| 561 | tf->lbah = gtf->tf[4]; /* 0x1f5 */ |
| 562 | tf->device = gtf->tf[5]; /* 0x1f6 */ |
| 563 | tf->command = gtf->tf[6]; /* 0x1f7 */ |
| 564 | } |
| 565 | |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 566 | static int ata_acpi_filter_tf(struct ata_device *dev, |
| 567 | const struct ata_taskfile *tf, |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 568 | const struct ata_taskfile *ptf) |
| 569 | { |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 570 | if (dev->gtf_filter & ATA_ACPI_FILTER_SETXFER) { |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 571 | /* libata doesn't use ACPI to configure transfer mode. |
| 572 | * It will only confuse device configuration. Skip. |
| 573 | */ |
| 574 | if (tf->command == ATA_CMD_SET_FEATURES && |
| 575 | tf->feature == SETFEATURES_XFER) |
| 576 | return 1; |
| 577 | } |
| 578 | |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 579 | if (dev->gtf_filter & ATA_ACPI_FILTER_LOCK) { |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 580 | /* BIOS writers, sorry but we don't wanna lock |
| 581 | * features unless the user explicitly said so. |
| 582 | */ |
| 583 | |
| 584 | /* DEVICE CONFIGURATION FREEZE LOCK */ |
| 585 | if (tf->command == ATA_CMD_CONF_OVERLAY && |
| 586 | tf->feature == ATA_DCO_FREEZE_LOCK) |
| 587 | return 1; |
| 588 | |
| 589 | /* SECURITY FREEZE LOCK */ |
| 590 | if (tf->command == ATA_CMD_SEC_FREEZE_LOCK) |
| 591 | return 1; |
| 592 | |
| 593 | /* SET MAX LOCK and SET MAX FREEZE LOCK */ |
| 594 | if ((!ptf || ptf->command != ATA_CMD_READ_NATIVE_MAX) && |
| 595 | tf->command == ATA_CMD_SET_MAX && |
| 596 | (tf->feature == ATA_SET_MAX_LOCK || |
| 597 | tf->feature == ATA_SET_MAX_FREEZE_LOCK)) |
| 598 | return 1; |
| 599 | } |
| 600 | |
Tejun Heo | fa5b561 | 2009-09-16 04:17:02 +0900 | [diff] [blame] | 601 | if (tf->command == ATA_CMD_SET_FEATURES && |
| 602 | tf->feature == SETFEATURES_SATA_ENABLE) { |
Tejun Heo | b344991 | 2008-07-06 23:15:03 +0900 | [diff] [blame] | 603 | /* inhibit enabling DIPM */ |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 604 | if (dev->gtf_filter & ATA_ACPI_FILTER_DIPM && |
Tejun Heo | b344991 | 2008-07-06 23:15:03 +0900 | [diff] [blame] | 605 | tf->nsect == SATA_DIPM) |
| 606 | return 1; |
Tejun Heo | fa5b561 | 2009-09-16 04:17:02 +0900 | [diff] [blame] | 607 | |
| 608 | /* inhibit FPDMA non-zero offset */ |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 609 | if (dev->gtf_filter & ATA_ACPI_FILTER_FPDMA_OFFSET && |
Tejun Heo | fa5b561 | 2009-09-16 04:17:02 +0900 | [diff] [blame] | 610 | (tf->nsect == SATA_FPDMA_OFFSET || |
| 611 | tf->nsect == SATA_FPDMA_IN_ORDER)) |
| 612 | return 1; |
| 613 | |
| 614 | /* inhibit FPDMA auto activation */ |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 615 | if (dev->gtf_filter & ATA_ACPI_FILTER_FPDMA_AA && |
Tejun Heo | fa5b561 | 2009-09-16 04:17:02 +0900 | [diff] [blame] | 616 | tf->nsect == SATA_FPDMA_AA) |
| 617 | return 1; |
Tejun Heo | b344991 | 2008-07-06 23:15:03 +0900 | [diff] [blame] | 618 | } |
| 619 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 620 | return 0; |
| 621 | } |
| 622 | |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 623 | /** |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 624 | * ata_acpi_run_tf - send taskfile registers to host controller |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 625 | * @dev: target ATA device |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 626 | * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7) |
| 627 | * |
Sergei Shtylyov | 3696df3 | 2011-02-04 22:04:17 +0300 | [diff] [blame] | 628 | * Outputs ATA taskfile to standard ATA host controller. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 629 | * Writes the control, feature, nsect, lbal, lbam, and lbah registers. |
| 630 | * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect, |
| 631 | * hob_lbal, hob_lbam, and hob_lbah. |
| 632 | * |
| 633 | * This function waits for idle (!BUSY and !DRQ) after writing |
| 634 | * registers. If the control register has a new value, this |
| 635 | * function also waits for idle after writing control and before |
| 636 | * writing the remaining registers. |
| 637 | * |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 638 | * LOCKING: |
| 639 | * EH context. |
| 640 | * |
| 641 | * RETURNS: |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 642 | * 1 if command is executed successfully. 0 if ignored, rejected or |
| 643 | * filtered out, -errno on other errors. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 644 | */ |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 645 | static int ata_acpi_run_tf(struct ata_device *dev, |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 646 | const struct ata_acpi_gtf *gtf, |
| 647 | const struct ata_acpi_gtf *prev_gtf) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 648 | { |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 649 | struct ata_taskfile *pptf = NULL; |
| 650 | struct ata_taskfile tf, ptf, rtf; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 651 | unsigned int err_mask; |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 652 | const char *level; |
Robert Hancock | 6521148 | 2009-07-14 20:43:39 -0600 | [diff] [blame] | 653 | const char *descr; |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 654 | char msg[60]; |
| 655 | int rc; |
Jeff Garzik | fc16c25 | 2007-02-24 21:05:01 -0500 | [diff] [blame] | 656 | |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 657 | if ((gtf->tf[0] == 0) && (gtf->tf[1] == 0) && (gtf->tf[2] == 0) |
| 658 | && (gtf->tf[3] == 0) && (gtf->tf[4] == 0) && (gtf->tf[5] == 0) |
| 659 | && (gtf->tf[6] == 0)) |
| 660 | return 0; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 661 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 662 | ata_acpi_gtf_to_tf(dev, gtf, &tf); |
| 663 | if (prev_gtf) { |
| 664 | ata_acpi_gtf_to_tf(dev, prev_gtf, &ptf); |
| 665 | pptf = &ptf; |
| 666 | } |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 667 | |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 668 | if (!ata_acpi_filter_tf(dev, &tf, pptf)) { |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 669 | rtf = tf; |
| 670 | err_mask = ata_exec_internal(dev, &rtf, NULL, |
| 671 | DMA_NONE, NULL, 0, 0); |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 672 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 673 | switch (err_mask) { |
| 674 | case 0: |
| 675 | level = KERN_DEBUG; |
| 676 | snprintf(msg, sizeof(msg), "succeeded"); |
| 677 | rc = 1; |
| 678 | break; |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 679 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 680 | case AC_ERR_DEV: |
| 681 | level = KERN_INFO; |
| 682 | snprintf(msg, sizeof(msg), |
| 683 | "rejected by device (Stat=0x%02x Err=0x%02x)", |
| 684 | rtf.command, rtf.feature); |
| 685 | rc = 0; |
| 686 | break; |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 687 | |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 688 | default: |
| 689 | level = KERN_ERR; |
| 690 | snprintf(msg, sizeof(msg), |
| 691 | "failed (Emask=0x%x Stat=0x%02x Err=0x%02x)", |
| 692 | err_mask, rtf.command, rtf.feature); |
| 693 | rc = -EIO; |
| 694 | break; |
| 695 | } |
| 696 | } else { |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 697 | level = KERN_INFO; |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 698 | snprintf(msg, sizeof(msg), "filtered out"); |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 699 | rc = 0; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 700 | } |
Robert Hancock | 6521148 | 2009-07-14 20:43:39 -0600 | [diff] [blame] | 701 | descr = ata_get_cmd_descript(tf.command); |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 702 | |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 703 | ata_dev_printk(dev, level, |
Robert Hancock | 6521148 | 2009-07-14 20:43:39 -0600 | [diff] [blame] | 704 | "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x (%s) %s\n", |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 705 | tf.command, tf.feature, tf.nsect, tf.lbal, |
Robert Hancock | 6521148 | 2009-07-14 20:43:39 -0600 | [diff] [blame] | 706 | tf.lbam, tf.lbah, tf.device, |
| 707 | (descr ? descr : "unknown"), msg); |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 708 | |
| 709 | return rc; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | /** |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 713 | * ata_acpi_exec_tfs - get then write drive taskfile settings |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 714 | * @dev: target ATA device |
Martin Olsson | 98a1708 | 2009-04-22 18:21:29 +0200 | [diff] [blame] | 715 | * @nr_executed: out parameter for the number of executed commands |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 716 | * |
Martin Olsson | 98a1708 | 2009-04-22 18:21:29 +0200 | [diff] [blame] | 717 | * Evaluate _GTF and execute returned taskfiles. |
Tejun Heo | 69b16a5 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 718 | * |
| 719 | * LOCKING: |
| 720 | * EH context. |
| 721 | * |
| 722 | * RETURNS: |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 723 | * Number of executed taskfiles on success, 0 if _GTF doesn't exist. |
| 724 | * -errno on other errors. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 725 | */ |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 726 | static int ata_acpi_exec_tfs(struct ata_device *dev, int *nr_executed) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 727 | { |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 728 | struct ata_acpi_gtf *gtf = NULL, *pgtf = NULL; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 729 | int gtf_count, i, rc; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 730 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 731 | /* get taskfiles */ |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 732 | rc = ata_dev_get_GTF(dev, >f); |
| 733 | if (rc < 0) |
| 734 | return rc; |
| 735 | gtf_count = rc; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 736 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 737 | /* execute them */ |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 738 | for (i = 0; i < gtf_count; i++, gtf++) { |
| 739 | rc = ata_acpi_run_tf(dev, gtf, pgtf); |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 740 | if (rc < 0) |
| 741 | break; |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 742 | if (rc) { |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 743 | (*nr_executed)++; |
Tejun Heo | 3264a8d | 2007-12-15 15:05:06 +0900 | [diff] [blame] | 744 | pgtf = gtf; |
| 745 | } |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 748 | ata_acpi_clear_gtf(dev); |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 749 | |
Tejun Heo | 0e8634b | 2007-12-15 15:05:05 +0900 | [diff] [blame] | 750 | if (rc < 0) |
| 751 | return rc; |
| 752 | return 0; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 755 | /** |
| 756 | * ata_acpi_push_id - send Identify data to drive |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 757 | * @dev: target ATA device |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 758 | * |
| 759 | * _SDD ACPI object: for SATA mode only |
| 760 | * Must be after Identify (Packet) Device -- uses its data |
| 761 | * ATM this function never returns a failure. It is an optional |
| 762 | * method and if it fails for whatever reason, we should still |
| 763 | * just keep going. |
Tejun Heo | 69b16a5 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 764 | * |
| 765 | * LOCKING: |
| 766 | * EH context. |
| 767 | * |
| 768 | * RETURNS: |
Tejun Heo | f240677 | 2009-11-18 22:24:21 +0900 | [diff] [blame] | 769 | * 0 on success, -ENOENT if _SDD doesn't exist, -errno on failure. |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 770 | */ |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 771 | static int ata_acpi_push_id(struct ata_device *dev) |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 772 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 773 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 774 | acpi_status status; |
| 775 | struct acpi_object_list input; |
| 776 | union acpi_object in_params[1]; |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 777 | |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 778 | if (ata_msg_probe(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 779 | ata_dev_dbg(dev, "%s: ix = %d, port#: %d\n", |
| 780 | __func__, dev->devno, ap->port_no); |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 781 | |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 782 | /* Give the drive Identify data to the drive via the _SDD method */ |
| 783 | /* _SDD: set up input parameters */ |
| 784 | input.count = 1; |
| 785 | input.pointer = in_params; |
| 786 | in_params[0].type = ACPI_TYPE_BUFFER; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 787 | in_params[0].buffer.length = sizeof(dev->id[0]) * ATA_ID_WORDS; |
| 788 | in_params[0].buffer.pointer = (u8 *)dev->id; |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 789 | /* Output buffer: _SDD has no output */ |
| 790 | |
| 791 | /* It's OK for _SDD to be missing too. */ |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 792 | swap_buf_le16(dev->id, ATA_ID_WORDS); |
Matthew Garrett | 30dcf76 | 2012-06-25 16:13:04 +0800 | [diff] [blame] | 793 | status = acpi_evaluate_object(ata_dev_acpi_handle(dev), "_SDD", &input, |
| 794 | NULL); |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 795 | swap_buf_le16(dev->id, ATA_ID_WORDS); |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 796 | |
Tejun Heo | f240677 | 2009-11-18 22:24:21 +0900 | [diff] [blame] | 797 | if (status == AE_NOT_FOUND) |
| 798 | return -ENOENT; |
| 799 | |
| 800 | if (ACPI_FAILURE(status)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 801 | ata_dev_warn(dev, "ACPI _SDD failed (AE 0x%x)\n", status); |
Tejun Heo | f240677 | 2009-11-18 22:24:21 +0900 | [diff] [blame] | 802 | return -EIO; |
| 803 | } |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 804 | |
Tejun Heo | f240677 | 2009-11-18 22:24:21 +0900 | [diff] [blame] | 805 | return 0; |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 808 | /** |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 809 | * ata_acpi_on_suspend - ATA ACPI hook called on suspend |
| 810 | * @ap: target ATA port |
| 811 | * |
| 812 | * This function is called when @ap is about to be suspended. All |
| 813 | * devices are already put to sleep but the port_suspend() callback |
| 814 | * hasn't been executed yet. Error return from this function aborts |
| 815 | * suspend. |
| 816 | * |
| 817 | * LOCKING: |
| 818 | * EH context. |
| 819 | * |
| 820 | * RETURNS: |
| 821 | * 0 on success, -errno on failure. |
| 822 | */ |
| 823 | int ata_acpi_on_suspend(struct ata_port *ap) |
| 824 | { |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 825 | /* nada */ |
| 826 | return 0; |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | /** |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 830 | * ata_acpi_on_resume - ATA ACPI hook called on resume |
| 831 | * @ap: target ATA port |
| 832 | * |
| 833 | * This function is called when @ap is resumed - right after port |
| 834 | * itself is resumed but before any EH action is taken. |
| 835 | * |
| 836 | * LOCKING: |
| 837 | * EH context. |
| 838 | */ |
| 839 | void ata_acpi_on_resume(struct ata_port *ap) |
| 840 | { |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 841 | const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 842 | struct ata_device *dev; |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 843 | |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 844 | if (ACPI_HANDLE(&ap->tdev) && gtm) { |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 845 | /* _GTM valid */ |
| 846 | |
| 847 | /* restore timing parameters */ |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 848 | ata_acpi_stm(ap, gtm); |
Tejun Heo | 64578a3de | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 849 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 850 | /* _GTF should immediately follow _STM so that it can |
| 851 | * use values set by _STM. Cache _GTF result and |
| 852 | * schedule _GTF. |
| 853 | */ |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 854 | ata_for_each_dev(dev, &ap->link, ALL) { |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 855 | ata_acpi_clear_gtf(dev); |
Shaohua Li | 48feb3c | 2008-03-25 16:50:45 +0800 | [diff] [blame] | 856 | if (ata_dev_enabled(dev) && |
Aaron Lu | c75da20 | 2014-03-14 13:46:09 +0800 | [diff] [blame] | 857 | ata_dev_acpi_handle(dev) && |
Shaohua Li | 48feb3c | 2008-03-25 16:50:45 +0800 | [diff] [blame] | 858 | ata_dev_get_GTF(dev, NULL) >= 0) |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 859 | dev->flags |= ATA_DFLAG_ACPI_PENDING; |
| 860 | } |
| 861 | } else { |
| 862 | /* SATA _GTF needs to be evaulated after _SDD and |
| 863 | * there's no reason to evaluate IDE _GTF early |
| 864 | * without _STM. Clear cache and schedule _GTF. |
| 865 | */ |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 866 | ata_for_each_dev(dev, &ap->link, ALL) { |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 867 | ata_acpi_clear_gtf(dev); |
Shaohua Li | 48feb3c | 2008-03-25 16:50:45 +0800 | [diff] [blame] | 868 | if (ata_dev_enabled(dev)) |
| 869 | dev->flags |= ATA_DFLAG_ACPI_PENDING; |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 870 | } |
| 871 | } |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 872 | } |
| 873 | |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 874 | static int ata_acpi_choose_suspend_state(struct ata_device *dev, bool runtime) |
Shaohua Li | bd3adca | 2007-11-02 09:32:38 +0800 | [diff] [blame] | 875 | { |
Aaron Lu | 2133420 | 2013-01-15 17:21:01 +0800 | [diff] [blame] | 876 | int d_max_in = ACPI_STATE_D3_COLD; |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 877 | if (!runtime) |
| 878 | goto out; |
Aaron Lu | 2133420 | 2013-01-15 17:21:01 +0800 | [diff] [blame] | 879 | |
| 880 | /* |
| 881 | * For ATAPI, runtime D3 cold is only allowed |
| 882 | * for ZPODD in zero power ready state |
| 883 | */ |
| 884 | if (dev->class == ATA_DEV_ATAPI && |
| 885 | !(zpodd_dev_enabled(dev) && zpodd_zpready(dev))) |
| 886 | d_max_in = ACPI_STATE_D3_HOT; |
| 887 | |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 888 | out: |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 889 | return acpi_pm_device_sleep_state(&dev->tdev, NULL, d_max_in); |
Aaron Lu | 2133420 | 2013-01-15 17:21:01 +0800 | [diff] [blame] | 890 | } |
| 891 | |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 892 | static void sata_acpi_set_state(struct ata_port *ap, pm_message_t state) |
| 893 | { |
| 894 | bool runtime = PMSG_IS_AUTO(state); |
Shaohua Li | bd3adca | 2007-11-02 09:32:38 +0800 | [diff] [blame] | 895 | struct ata_device *dev; |
Lin Ming | febe53b | 2012-06-25 16:13:05 +0800 | [diff] [blame] | 896 | acpi_handle handle; |
Lin Ming | 3bd46600a7 | 2012-06-25 16:13:06 +0800 | [diff] [blame] | 897 | int acpi_state; |
Shaohua Li | bd3adca | 2007-11-02 09:32:38 +0800 | [diff] [blame] | 898 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 899 | ata_for_each_dev(dev, &ap->link, ENABLED) { |
Lin Ming | febe53b | 2012-06-25 16:13:05 +0800 | [diff] [blame] | 900 | handle = ata_dev_acpi_handle(dev); |
Lin Ming | 3bd46600a7 | 2012-06-25 16:13:06 +0800 | [diff] [blame] | 901 | if (!handle) |
| 902 | continue; |
| 903 | |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 904 | if (!(state.event & PM_EVENT_RESUME)) { |
| 905 | acpi_state = ata_acpi_choose_suspend_state(dev, runtime); |
| 906 | if (acpi_state == ACPI_STATE_D0) |
| 907 | continue; |
| 908 | if (runtime && zpodd_dev_enabled(dev) && |
| 909 | acpi_state == ACPI_STATE_D3_COLD) |
| 910 | zpodd_enable_run_wake(dev); |
| 911 | acpi_bus_set_power(handle, acpi_state); |
Lin Ming | 3bd46600a7 | 2012-06-25 16:13:06 +0800 | [diff] [blame] | 912 | } else { |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 913 | if (runtime && zpodd_dev_enabled(dev)) |
| 914 | zpodd_disable_run_wake(dev); |
Lin Ming | 3bd46600a7 | 2012-06-25 16:13:06 +0800 | [diff] [blame] | 915 | acpi_bus_set_power(handle, ACPI_STATE_D0); |
| 916 | } |
Shaohua Li | bd3adca | 2007-11-02 09:32:38 +0800 | [diff] [blame] | 917 | } |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 918 | } |
Lin Ming | febe53b | 2012-06-25 16:13:05 +0800 | [diff] [blame] | 919 | |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 920 | /* ACPI spec requires _PS0 when IDE power on and _PS3 when power off */ |
| 921 | static void pata_acpi_set_state(struct ata_port *ap, pm_message_t state) |
| 922 | { |
| 923 | struct ata_device *dev; |
| 924 | acpi_handle port_handle; |
| 925 | |
Aaron Lu | f1bc1e4 | 2013-08-23 10:17:54 +0800 | [diff] [blame] | 926 | port_handle = ACPI_HANDLE(&ap->tdev); |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 927 | if (!port_handle) |
| 928 | return; |
| 929 | |
| 930 | /* channel first and then drives for power on and vica versa |
| 931 | for power off */ |
| 932 | if (state.event & PM_EVENT_RESUME) |
| 933 | acpi_bus_set_power(port_handle, ACPI_STATE_D0); |
| 934 | |
| 935 | ata_for_each_dev(dev, &ap->link, ENABLED) { |
| 936 | acpi_handle dev_handle = ata_dev_acpi_handle(dev); |
| 937 | if (!dev_handle) |
| 938 | continue; |
| 939 | |
| 940 | acpi_bus_set_power(dev_handle, state.event & PM_EVENT_RESUME ? |
Rafael J. Wysocki | 8ad928d | 2013-07-30 14:36:20 +0200 | [diff] [blame] | 941 | ACPI_STATE_D0 : ACPI_STATE_D3_COLD); |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | if (!(state.event & PM_EVENT_RESUME)) |
Rafael J. Wysocki | 8ad928d | 2013-07-30 14:36:20 +0200 | [diff] [blame] | 945 | acpi_bus_set_power(port_handle, ACPI_STATE_D3_COLD); |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 946 | } |
| 947 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 948 | /** |
| 949 | * ata_acpi_set_state - set the port power state |
| 950 | * @ap: target ATA port |
| 951 | * @state: state, on/off |
| 952 | * |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 953 | * This function sets a proper ACPI D state for the device on |
| 954 | * system and runtime PM operations. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 955 | */ |
| 956 | void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) |
| 957 | { |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 958 | if (ap->flags & ATA_FLAG_ACPI_SATA) |
| 959 | sata_acpi_set_state(ap, state); |
| 960 | else |
| 961 | pata_acpi_set_state(ap, state); |
Shaohua Li | bd3adca | 2007-11-02 09:32:38 +0800 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | /** |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 965 | * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration |
| 966 | * @dev: target ATA device |
| 967 | * |
| 968 | * This function is called when @dev is about to be configured. |
| 969 | * IDENTIFY data might have been modified after this hook is run. |
| 970 | * |
| 971 | * LOCKING: |
| 972 | * EH context. |
| 973 | * |
| 974 | * RETURNS: |
| 975 | * Positive number if IDENTIFY data needs to be refreshed, 0 if not, |
| 976 | * -errno on failure. |
| 977 | */ |
| 978 | int ata_acpi_on_devcfg(struct ata_device *dev) |
| 979 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 980 | struct ata_port *ap = dev->link->ap; |
| 981 | struct ata_eh_context *ehc = &ap->link.eh_context; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 982 | int acpi_sata = ap->flags & ATA_FLAG_ACPI_SATA; |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 983 | int nr_executed = 0; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 984 | int rc; |
| 985 | |
Matthew Garrett | 30dcf76 | 2012-06-25 16:13:04 +0800 | [diff] [blame] | 986 | if (!ata_dev_acpi_handle(dev)) |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 987 | return 0; |
| 988 | |
| 989 | /* do we need to do _GTF? */ |
| 990 | if (!(dev->flags & ATA_DFLAG_ACPI_PENDING) && |
| 991 | !(acpi_sata && (ehc->i.flags & ATA_EHI_DID_HARDRESET))) |
| 992 | return 0; |
| 993 | |
| 994 | /* do _SDD if SATA */ |
| 995 | if (acpi_sata) { |
| 996 | rc = ata_acpi_push_id(dev); |
Tejun Heo | f240677 | 2009-11-18 22:24:21 +0900 | [diff] [blame] | 997 | if (rc && rc != -ENOENT) |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 998 | goto acpi_err; |
| 999 | } |
| 1000 | |
| 1001 | /* do _GTF */ |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 1002 | rc = ata_acpi_exec_tfs(dev, &nr_executed); |
| 1003 | if (rc) |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1004 | goto acpi_err; |
| 1005 | |
| 1006 | dev->flags &= ~ATA_DFLAG_ACPI_PENDING; |
| 1007 | |
| 1008 | /* refresh IDENTIFY page if any _GTF command has been executed */ |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 1009 | if (nr_executed) { |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1010 | rc = ata_dev_reread_id(dev, 0); |
| 1011 | if (rc < 0) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1012 | ata_dev_err(dev, |
| 1013 | "failed to IDENTIFY after ACPI commands\n"); |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1014 | return rc; |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | return 0; |
| 1019 | |
| 1020 | acpi_err: |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 1021 | /* ignore evaluation failure if we can continue safely */ |
| 1022 | if (rc == -EINVAL && !nr_executed && !(ap->pflags & ATA_PFLAG_FROZEN)) |
| 1023 | return 0; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1024 | |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 1025 | /* fail and let EH retry once more for unknown IO errors */ |
| 1026 | if (!(dev->flags & ATA_DFLAG_ACPI_FAILED)) { |
| 1027 | dev->flags |= ATA_DFLAG_ACPI_FAILED; |
| 1028 | return rc; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1029 | } |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 1030 | |
Aaron Lu | 0d0cdb0 | 2012-11-26 13:55:25 +0800 | [diff] [blame] | 1031 | dev->flags |= ATA_DFLAG_ACPI_DISABLED; |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1032 | ata_dev_warn(dev, "ACPI: failed the second time, disabled\n"); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame] | 1033 | |
| 1034 | /* We can safely continue if no _GTF command has been executed |
| 1035 | * and port is not frozen. |
| 1036 | */ |
| 1037 | if (!nr_executed && !(ap->pflags & ATA_PFLAG_FROZEN)) |
| 1038 | return 0; |
| 1039 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1040 | return rc; |
| 1041 | } |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 1042 | |
| 1043 | /** |
| 1044 | * ata_acpi_on_disable - ATA ACPI hook called when a device is disabled |
| 1045 | * @dev: target ATA device |
| 1046 | * |
| 1047 | * This function is called when @dev is about to be disabled. |
| 1048 | * |
| 1049 | * LOCKING: |
| 1050 | * EH context. |
| 1051 | */ |
| 1052 | void ata_acpi_on_disable(struct ata_device *dev) |
| 1053 | { |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 1054 | ata_acpi_clear_gtf(dev); |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 1055 | } |