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