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 | |
| 9 | #include <linux/ata.h> |
| 10 | #include <linux/delay.h> |
| 11 | #include <linux/device.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/acpi.h> |
| 15 | #include <linux/libata.h> |
| 16 | #include <linux/pci.h> |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 17 | #include <scsi/scsi_device.h> |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 18 | #include "libata.h" |
| 19 | |
| 20 | #include <acpi/acpi_bus.h> |
| 21 | #include <acpi/acnames.h> |
| 22 | #include <acpi/acnamesp.h> |
| 23 | #include <acpi/acparser.h> |
| 24 | #include <acpi/acexcep.h> |
| 25 | #include <acpi/acmacros.h> |
| 26 | #include <acpi/actypes.h> |
| 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 | |
Tejun Heo | d0df8b5d | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 50 | /** |
| 51 | * ata_acpi_associate_sata_port - associate SATA port with ACPI objects |
| 52 | * @ap: target SATA port |
| 53 | * |
| 54 | * Look up ACPI objects associated with @ap and initialize acpi_handle |
| 55 | * fields of @ap, the port and devices accordingly. |
| 56 | * |
| 57 | * LOCKING: |
| 58 | * EH context. |
| 59 | * |
| 60 | * RETURNS: |
| 61 | * 0 on success, -errno on failure. |
| 62 | */ |
| 63 | void ata_acpi_associate_sata_port(struct ata_port *ap) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 64 | { |
Tejun Heo | d0df8b5d | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 65 | WARN_ON(!(ap->flags & ATA_FLAG_ACPI_SATA)); |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 66 | |
Tejun Heo | d0df8b5d | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 67 | if (!ap->nr_pmp_links) { |
| 68 | acpi_integer adr = SATA_ADR(ap->port_no, NO_PORT_MULT); |
| 69 | |
| 70 | ap->link.device->acpi_handle = |
| 71 | acpi_get_child(ap->host->acpi_handle, adr); |
| 72 | } else { |
| 73 | struct ata_link *link; |
| 74 | |
| 75 | ap->link.device->acpi_handle = NULL; |
| 76 | |
| 77 | ata_port_for_each_link(link, ap) { |
| 78 | acpi_integer adr = SATA_ADR(ap->port_no, link->pmp); |
| 79 | |
| 80 | link->device->acpi_handle = |
| 81 | acpi_get_child(ap->host->acpi_handle, adr); |
| 82 | } |
| 83 | } |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 84 | } |
Alan Cox | ca42663 | 2007-03-08 23:13:50 +0000 | [diff] [blame] | 85 | |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 86 | static void ata_acpi_associate_ide_port(struct ata_port *ap) |
| 87 | { |
| 88 | int max_devices, i; |
| 89 | |
| 90 | ap->acpi_handle = acpi_get_child(ap->host->acpi_handle, ap->port_no); |
| 91 | if (!ap->acpi_handle) |
| 92 | return; |
| 93 | |
| 94 | max_devices = 1; |
| 95 | if (ap->flags & ATA_FLAG_SLAVE_POSS) |
| 96 | max_devices++; |
| 97 | |
| 98 | for (i = 0; i < max_devices; i++) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 99 | struct ata_device *dev = &ap->link.device[i]; |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 100 | |
| 101 | dev->acpi_handle = acpi_get_child(ap->acpi_handle, i); |
| 102 | } |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 103 | |
| 104 | if (ata_acpi_gtm(ap, &ap->__acpi_init_gtm) == 0) |
| 105 | ap->pflags |= ATA_PFLAG_INIT_GTM_VALID; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 108 | static void ata_acpi_handle_hotplug(struct ata_port *ap, struct kobject *kobj, |
| 109 | u32 event) |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 110 | { |
| 111 | char event_string[12]; |
| 112 | char *envp[] = { event_string, NULL }; |
| 113 | struct ata_eh_info *ehi = &ap->link.eh_info; |
| 114 | |
| 115 | if (event == 0 || event == 1) { |
| 116 | unsigned long flags; |
| 117 | spin_lock_irqsave(ap->lock, flags); |
| 118 | ata_ehi_clear_desc(ehi); |
| 119 | ata_ehi_push_desc(ehi, "ACPI event"); |
| 120 | ata_ehi_hotplugged(ehi); |
| 121 | ata_port_freeze(ap); |
| 122 | spin_unlock_irqrestore(ap->lock, flags); |
| 123 | } |
| 124 | |
| 125 | if (kobj) { |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 126 | sprintf(event_string, "BAY_EVENT=%d", event); |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 127 | kobject_uevent_env(kobj, KOBJ_CHANGE, envp); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | static void ata_acpi_dev_notify(acpi_handle handle, u32 event, void *data) |
| 132 | { |
| 133 | struct ata_device *dev = data; |
| 134 | struct kobject *kobj = NULL; |
| 135 | |
| 136 | if (dev->sdev) |
| 137 | kobj = &dev->sdev->sdev_gendev.kobj; |
| 138 | |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 139 | ata_acpi_handle_hotplug(dev->link->ap, kobj, event); |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static void ata_acpi_ap_notify(acpi_handle handle, u32 event, void *data) |
| 143 | { |
| 144 | struct ata_port *ap = data; |
| 145 | |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 146 | ata_acpi_handle_hotplug(ap, &ap->dev->kobj, event); |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 149 | /** |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 150 | * ata_acpi_associate - associate ATA host with ACPI objects |
| 151 | * @host: target ATA host |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 152 | * |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 153 | * Look up ACPI objects associated with @host and initialize |
| 154 | * acpi_handle fields of @host, its ports and devices accordingly. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 155 | * |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 156 | * LOCKING: |
| 157 | * EH context. |
| 158 | * |
| 159 | * RETURNS: |
| 160 | * 0 on success, -errno on failure. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 161 | */ |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 162 | void ata_acpi_associate(struct ata_host *host) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 163 | { |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 164 | int i, j; |
Alan Cox | ca42663 | 2007-03-08 23:13:50 +0000 | [diff] [blame] | 165 | |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 166 | if (!is_pci_dev(host->dev) || libata_noacpi) |
| 167 | return; |
Alan Cox | ca42663 | 2007-03-08 23:13:50 +0000 | [diff] [blame] | 168 | |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 169 | host->acpi_handle = DEVICE_ACPI_HANDLE(host->dev); |
| 170 | if (!host->acpi_handle) |
| 171 | return; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 172 | |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 173 | for (i = 0; i < host->n_ports; i++) { |
| 174 | struct ata_port *ap = host->ports[i]; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 175 | |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 176 | if (host->ports[0]->flags & ATA_FLAG_ACPI_SATA) |
| 177 | ata_acpi_associate_sata_port(ap); |
| 178 | else |
| 179 | ata_acpi_associate_ide_port(ap); |
Matthew Garrett | 237d844 | 2007-10-03 01:24:16 +0100 | [diff] [blame] | 180 | |
| 181 | if (ap->acpi_handle) |
| 182 | acpi_install_notify_handler (ap->acpi_handle, |
| 183 | ACPI_SYSTEM_NOTIFY, |
| 184 | ata_acpi_ap_notify, |
| 185 | ap); |
| 186 | |
| 187 | for (j = 0; j < ata_link_max_devices(&ap->link); j++) { |
| 188 | struct ata_device *dev = &ap->link.device[j]; |
| 189 | |
| 190 | if (dev->acpi_handle) |
| 191 | acpi_install_notify_handler (dev->acpi_handle, |
| 192 | ACPI_SYSTEM_NOTIFY, |
| 193 | ata_acpi_dev_notify, |
| 194 | dev); |
| 195 | } |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 196 | } |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /** |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 200 | * ata_acpi_dissociate - dissociate ATA host from ACPI objects |
| 201 | * @host: target ATA host |
| 202 | * |
| 203 | * This function is called during driver detach after the whole host |
| 204 | * is shut down. |
| 205 | * |
| 206 | * LOCKING: |
| 207 | * EH context. |
| 208 | */ |
| 209 | void ata_acpi_dissociate(struct ata_host *host) |
| 210 | { |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 211 | int i; |
| 212 | |
| 213 | /* Restore initial _GTM values so that driver which attaches |
| 214 | * afterward can use them too. |
| 215 | */ |
| 216 | for (i = 0; i < host->n_ports; i++) { |
| 217 | struct ata_port *ap = host->ports[i]; |
| 218 | const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); |
| 219 | |
| 220 | if (ap->acpi_handle && gtm) |
| 221 | ata_acpi_stm(ap, gtm); |
| 222 | } |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /** |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 226 | * ata_acpi_gtm - execute _GTM |
| 227 | * @ap: target ATA port |
| 228 | * @gtm: out parameter for _GTM result |
| 229 | * |
| 230 | * Evaluate _GTM and store the result in @gtm. |
| 231 | * |
| 232 | * LOCKING: |
| 233 | * EH context. |
| 234 | * |
| 235 | * RETURNS: |
| 236 | * 0 on success, -ENOENT if _GTM doesn't exist, -errno on failure. |
| 237 | */ |
Tejun Heo | 0d02f0b | 2007-12-15 15:04:57 +0900 | [diff] [blame] | 238 | int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *gtm) |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 239 | { |
| 240 | struct acpi_buffer output = { .length = ACPI_ALLOCATE_BUFFER }; |
| 241 | union acpi_object *out_obj; |
| 242 | acpi_status status; |
| 243 | int rc = 0; |
| 244 | |
| 245 | status = acpi_evaluate_object(ap->acpi_handle, "_GTM", NULL, &output); |
| 246 | |
| 247 | rc = -ENOENT; |
| 248 | if (status == AE_NOT_FOUND) |
| 249 | goto out_free; |
| 250 | |
| 251 | rc = -EINVAL; |
| 252 | if (ACPI_FAILURE(status)) { |
| 253 | ata_port_printk(ap, KERN_ERR, |
| 254 | "ACPI get timing mode failed (AE 0x%x)\n", |
| 255 | status); |
| 256 | goto out_free; |
| 257 | } |
| 258 | |
| 259 | out_obj = output.pointer; |
| 260 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
| 261 | ata_port_printk(ap, KERN_WARNING, |
| 262 | "_GTM returned unexpected object type 0x%x\n", |
| 263 | out_obj->type); |
| 264 | |
| 265 | goto out_free; |
| 266 | } |
| 267 | |
| 268 | if (out_obj->buffer.length != sizeof(struct ata_acpi_gtm)) { |
| 269 | ata_port_printk(ap, KERN_ERR, |
| 270 | "_GTM returned invalid length %d\n", |
| 271 | out_obj->buffer.length); |
| 272 | goto out_free; |
| 273 | } |
| 274 | |
| 275 | memcpy(gtm, out_obj->buffer.pointer, sizeof(struct ata_acpi_gtm)); |
| 276 | rc = 0; |
| 277 | out_free: |
| 278 | kfree(output.pointer); |
| 279 | return rc; |
| 280 | } |
| 281 | |
Alan Cox | badff03 | 2007-10-04 21:28:18 +0100 | [diff] [blame] | 282 | EXPORT_SYMBOL_GPL(ata_acpi_gtm); |
| 283 | |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 284 | /** |
| 285 | * ata_acpi_stm - execute _STM |
| 286 | * @ap: target ATA port |
| 287 | * @stm: timing parameter to _STM |
| 288 | * |
| 289 | * Evaluate _STM with timing parameter @stm. |
| 290 | * |
| 291 | * LOCKING: |
| 292 | * EH context. |
| 293 | * |
| 294 | * RETURNS: |
| 295 | * 0 on success, -ENOENT if _STM doesn't exist, -errno on failure. |
| 296 | */ |
Tejun Heo | 0d02f0b | 2007-12-15 15:04:57 +0900 | [diff] [blame] | 297 | int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm) |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 298 | { |
| 299 | acpi_status status; |
Tejun Heo | 0d02f0b | 2007-12-15 15:04:57 +0900 | [diff] [blame] | 300 | struct ata_acpi_gtm stm_buf = *stm; |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 301 | struct acpi_object_list input; |
| 302 | union acpi_object in_params[3]; |
| 303 | |
| 304 | in_params[0].type = ACPI_TYPE_BUFFER; |
| 305 | in_params[0].buffer.length = sizeof(struct ata_acpi_gtm); |
Tejun Heo | 0d02f0b | 2007-12-15 15:04:57 +0900 | [diff] [blame] | 306 | in_params[0].buffer.pointer = (u8 *)&stm_buf; |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 307 | /* Buffers for id may need byteswapping ? */ |
| 308 | in_params[1].type = ACPI_TYPE_BUFFER; |
| 309 | in_params[1].buffer.length = 512; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 310 | in_params[1].buffer.pointer = (u8 *)ap->link.device[0].id; |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 311 | in_params[2].type = ACPI_TYPE_BUFFER; |
| 312 | in_params[2].buffer.length = 512; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 313 | in_params[2].buffer.pointer = (u8 *)ap->link.device[1].id; |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 314 | |
| 315 | input.count = 3; |
| 316 | input.pointer = in_params; |
| 317 | |
| 318 | status = acpi_evaluate_object(ap->acpi_handle, "_STM", &input, NULL); |
| 319 | |
| 320 | if (status == AE_NOT_FOUND) |
| 321 | return -ENOENT; |
| 322 | if (ACPI_FAILURE(status)) { |
| 323 | ata_port_printk(ap, KERN_ERR, |
| 324 | "ACPI set timing mode failed (status=0x%x)\n", status); |
| 325 | return -EINVAL; |
| 326 | } |
| 327 | return 0; |
| 328 | } |
| 329 | |
Alan Cox | badff03 | 2007-10-04 21:28:18 +0100 | [diff] [blame] | 330 | EXPORT_SYMBOL_GPL(ata_acpi_stm); |
| 331 | |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 332 | /** |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 333 | * ata_dev_get_GTF - get the drive bootup default taskfile settings |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 334 | * @dev: target ATA device |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 335 | * @gtf: output parameter for buffer containing _GTF taskfile arrays |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 336 | * |
| 337 | * This applies to both PATA and SATA drives. |
| 338 | * |
| 339 | * The _GTF method has no input parameters. |
| 340 | * It returns a variable number of register set values (registers |
| 341 | * hex 1F1..1F7, taskfiles). |
| 342 | * The <variable number> is not known in advance, so have ACPI-CA |
| 343 | * allocate the buffer as needed and return it, then free it later. |
| 344 | * |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 345 | * LOCKING: |
| 346 | * EH context. |
| 347 | * |
| 348 | * RETURNS: |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 349 | * Number of taskfiles on success, 0 if _GTF doesn't exist. -EINVAL |
| 350 | * if _GTF is invalid. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 351 | */ |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 352 | 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] | 353 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 354 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 355 | acpi_status status; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 356 | struct acpi_buffer output; |
| 357 | union acpi_object *out_obj; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 358 | int rc = 0; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 359 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 360 | /* if _GTF is cached, use the cached value */ |
| 361 | if (dev->gtf_cache) { |
| 362 | out_obj = dev->gtf_cache; |
| 363 | goto done; |
| 364 | } |
| 365 | |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 366 | /* set up output buffer */ |
| 367 | output.length = ACPI_ALLOCATE_BUFFER; |
| 368 | output.pointer = NULL; /* ACPI-CA sets this; save/free it later */ |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 369 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 370 | if (ata_msg_probe(ap)) |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 371 | ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n", |
Tejun Heo | 878d4fe | 2007-02-21 16:36:33 +0900 | [diff] [blame] | 372 | __FUNCTION__, ap->port_no); |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 373 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 374 | /* _GTF has no input parameters */ |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 375 | status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output); |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 376 | out_obj = dev->gtf_cache = output.pointer; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 377 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 378 | if (ACPI_FAILURE(status)) { |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 379 | if (status != AE_NOT_FOUND) { |
| 380 | ata_dev_printk(dev, KERN_WARNING, |
| 381 | "_GTF evaluation failed (AE 0x%x)\n", |
| 382 | status); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 383 | rc = -EINVAL; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 384 | } |
| 385 | goto out_free; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | if (!output.length || !output.pointer) { |
| 389 | if (ata_msg_probe(ap)) |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 390 | ata_dev_printk(dev, KERN_DEBUG, "%s: Run _GTF: " |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 391 | "length or ptr is NULL (0x%llx, 0x%p)\n", |
| 392 | __FUNCTION__, |
| 393 | (unsigned long long)output.length, |
| 394 | output.pointer); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 395 | rc = -EINVAL; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 396 | goto out_free; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 399 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
Tejun Heo | 69b16a5 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 400 | ata_dev_printk(dev, KERN_WARNING, |
| 401 | "_GTF unexpected object type 0x%x\n", |
| 402 | out_obj->type); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 403 | rc = -EINVAL; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 404 | goto out_free; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 407 | if (out_obj->buffer.length % REGS_PER_GTF) { |
Tejun Heo | 69b16a5 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 408 | ata_dev_printk(dev, KERN_WARNING, |
| 409 | "unexpected _GTF length (%d)\n", |
| 410 | out_obj->buffer.length); |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 411 | rc = -EINVAL; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 412 | goto out_free; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 415 | done: |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 416 | rc = out_obj->buffer.length / REGS_PER_GTF; |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 417 | if (gtf) { |
| 418 | *gtf = (void *)out_obj->buffer.pointer; |
| 419 | if (ata_msg_probe(ap)) |
| 420 | ata_dev_printk(dev, KERN_DEBUG, |
| 421 | "%s: returning gtf=%p, gtf_count=%d\n", |
| 422 | __FUNCTION__, *gtf, rc); |
| 423 | } |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 424 | return rc; |
| 425 | |
| 426 | out_free: |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 427 | ata_acpi_clear_gtf(dev); |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 428 | return rc; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | /** |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 432 | * ata_acpi_cbl_80wire - Check for 80 wire cable |
| 433 | * @ap: Port to check |
| 434 | * |
| 435 | * Return 1 if the ACPI mode data for this port indicates the BIOS selected |
| 436 | * an 80wire mode. |
| 437 | */ |
| 438 | |
| 439 | int ata_acpi_cbl_80wire(struct ata_port *ap) |
| 440 | { |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 441 | const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 442 | int valid = 0; |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 443 | |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 444 | if (!gtm) |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 445 | return 0; |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 446 | |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 447 | /* Split timing, DMA enabled */ |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 448 | if ((gtm->flags & 0x11) == 0x11 && gtm->drive[0].dma < 55) |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 449 | valid |= 1; |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 450 | if ((gtm->flags & 0x14) == 0x14 && gtm->drive[1].dma < 55) |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 451 | valid |= 2; |
| 452 | /* Shared timing, DMA enabled */ |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 453 | if ((gtm->flags & 0x11) == 0x01 && gtm->drive[0].dma < 55) |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 454 | valid |= 1; |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 455 | if ((gtm->flags & 0x14) == 0x04 && gtm->drive[0].dma < 55) |
Alan Cox | e1ddb4b | 2007-08-16 02:33:36 -0400 | [diff] [blame] | 456 | valid |= 2; |
| 457 | |
| 458 | /* Drive check */ |
| 459 | if ((valid & 1) && ata_dev_enabled(&ap->link.device[0])) |
| 460 | return 1; |
| 461 | if ((valid & 2) && ata_dev_enabled(&ap->link.device[1])) |
| 462 | return 1; |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire); |
| 467 | |
| 468 | /** |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 469 | * taskfile_load_raw - send taskfile registers to host controller |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 470 | * @dev: target ATA device |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 471 | * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7) |
| 472 | * |
| 473 | * Outputs ATA taskfile to standard ATA host controller using MMIO |
| 474 | * or PIO as indicated by the ATA_FLAG_MMIO flag. |
| 475 | * Writes the control, feature, nsect, lbal, lbam, and lbah registers. |
| 476 | * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect, |
| 477 | * hob_lbal, hob_lbam, and hob_lbah. |
| 478 | * |
| 479 | * This function waits for idle (!BUSY and !DRQ) after writing |
| 480 | * registers. If the control register has a new value, this |
| 481 | * function also waits for idle after writing control and before |
| 482 | * writing the remaining registers. |
| 483 | * |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 484 | * LOCKING: |
| 485 | * EH context. |
| 486 | * |
| 487 | * RETURNS: |
| 488 | * 0 on success, -errno on failure. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 489 | */ |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 490 | static int taskfile_load_raw(struct ata_device *dev, |
| 491 | const struct ata_acpi_gtf *gtf) |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 492 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 493 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 494 | struct ata_taskfile tf, rtf; |
| 495 | unsigned int err_mask; |
Jeff Garzik | fc16c25 | 2007-02-24 21:05:01 -0500 | [diff] [blame] | 496 | |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 497 | if ((gtf->tf[0] == 0) && (gtf->tf[1] == 0) && (gtf->tf[2] == 0) |
| 498 | && (gtf->tf[3] == 0) && (gtf->tf[4] == 0) && (gtf->tf[5] == 0) |
| 499 | && (gtf->tf[6] == 0)) |
| 500 | return 0; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 501 | |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 502 | ata_tf_init(dev, &tf); |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 503 | |
Jeff Garzik | fc16c25 | 2007-02-24 21:05:01 -0500 | [diff] [blame] | 504 | /* convert gtf to tf */ |
| 505 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */ |
Tejun Heo | 48be6b1 | 2007-04-23 02:06:46 +0900 | [diff] [blame] | 506 | tf.protocol = ATA_PROT_NODATA; |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 507 | tf.feature = gtf->tf[0]; /* 0x1f1 */ |
| 508 | tf.nsect = gtf->tf[1]; /* 0x1f2 */ |
| 509 | tf.lbal = gtf->tf[2]; /* 0x1f3 */ |
| 510 | tf.lbam = gtf->tf[3]; /* 0x1f4 */ |
| 511 | tf.lbah = gtf->tf[4]; /* 0x1f5 */ |
| 512 | tf.device = gtf->tf[5]; /* 0x1f6 */ |
| 513 | tf.command = gtf->tf[6]; /* 0x1f7 */ |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 514 | |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 515 | if (ata_msg_probe(ap)) |
| 516 | ata_dev_printk(dev, KERN_DEBUG, "executing ACPI cmd " |
| 517 | "%02x/%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 518 | tf.command, tf.feature, tf.nsect, |
| 519 | tf.lbal, tf.lbam, tf.lbah, tf.device); |
| 520 | |
| 521 | rtf = tf; |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 522 | err_mask = ata_exec_internal(dev, &rtf, NULL, DMA_NONE, NULL, 0, 0); |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 523 | if (err_mask) { |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 524 | ata_dev_printk(dev, KERN_ERR, |
Tejun Heo | 4700c4b | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 525 | "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x failed " |
| 526 | "(Emask=0x%x Stat=0x%02x Err=0x%02x)\n", |
| 527 | tf.command, tf.feature, tf.nsect, tf.lbal, tf.lbam, |
| 528 | tf.lbah, tf.device, err_mask, rtf.command, rtf.feature); |
| 529 | return -EIO; |
| 530 | } |
| 531 | |
| 532 | return 0; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /** |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 536 | * ata_acpi_exec_tfs - get then write drive taskfile settings |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 537 | * @dev: target ATA device |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 538 | * @nr_executed: out paramter for the number of executed commands |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 539 | * |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 540 | * Evaluate _GTF and excute returned taskfiles. |
Tejun Heo | 69b16a5 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 541 | * |
| 542 | * LOCKING: |
| 543 | * EH context. |
| 544 | * |
| 545 | * RETURNS: |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 546 | * Number of executed taskfiles on success, 0 if _GTF doesn't exist. |
| 547 | * -errno on other errors. |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 548 | */ |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 549 | 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] | 550 | { |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 551 | struct ata_acpi_gtf *gtf = NULL; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 552 | int gtf_count, i, rc; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 553 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 554 | /* get taskfiles */ |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 555 | rc = ata_dev_get_GTF(dev, >f); |
| 556 | if (rc < 0) |
| 557 | return rc; |
| 558 | gtf_count = rc; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 559 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 560 | /* execute them */ |
| 561 | for (i = 0, rc = 0; i < gtf_count; i++) { |
| 562 | int tmp; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 563 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 564 | /* ACPI errors are eventually ignored. Run till the |
| 565 | * end even after errors. |
| 566 | */ |
| 567 | tmp = taskfile_load_raw(dev, gtf++); |
| 568 | if (!rc) |
| 569 | rc = tmp; |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 570 | |
| 571 | (*nr_executed)++; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 574 | ata_acpi_clear_gtf(dev); |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 575 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 576 | return rc; |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 579 | /** |
| 580 | * ata_acpi_push_id - send Identify data to drive |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 581 | * @dev: target ATA device |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 582 | * |
| 583 | * _SDD ACPI object: for SATA mode only |
| 584 | * Must be after Identify (Packet) Device -- uses its data |
| 585 | * ATM this function never returns a failure. It is an optional |
| 586 | * method and if it fails for whatever reason, we should still |
| 587 | * just keep going. |
Tejun Heo | 69b16a5 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 588 | * |
| 589 | * LOCKING: |
| 590 | * EH context. |
| 591 | * |
| 592 | * RETURNS: |
| 593 | * 0 on success, -errno on failure. |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 594 | */ |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 595 | static int ata_acpi_push_id(struct ata_device *dev) |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 596 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 597 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 598 | int err; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 599 | acpi_status status; |
| 600 | struct acpi_object_list input; |
| 601 | union acpi_object in_params[1]; |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 602 | |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 603 | if (ata_msg_probe(ap)) |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 604 | ata_dev_printk(dev, KERN_DEBUG, "%s: ix = %d, port#: %d\n", |
| 605 | __FUNCTION__, dev->devno, ap->port_no); |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 606 | |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 607 | /* Give the drive Identify data to the drive via the _SDD method */ |
| 608 | /* _SDD: set up input parameters */ |
| 609 | input.count = 1; |
| 610 | input.pointer = in_params; |
| 611 | in_params[0].type = ACPI_TYPE_BUFFER; |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 612 | in_params[0].buffer.length = sizeof(dev->id[0]) * ATA_ID_WORDS; |
| 613 | in_params[0].buffer.pointer = (u8 *)dev->id; |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 614 | /* Output buffer: _SDD has no output */ |
| 615 | |
| 616 | /* It's OK for _SDD to be missing too. */ |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 617 | swap_buf_le16(dev->id, ATA_ID_WORDS); |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 618 | status = acpi_evaluate_object(dev->acpi_handle, "_SDD", &input, NULL); |
Tejun Heo | 3a32a8e | 2007-05-05 23:50:38 +0900 | [diff] [blame] | 619 | swap_buf_le16(dev->id, ATA_ID_WORDS); |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 620 | |
| 621 | err = ACPI_FAILURE(status) ? -EIO : 0; |
Tejun Heo | 69b16a5 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 622 | if (err < 0) |
| 623 | ata_dev_printk(dev, KERN_WARNING, |
| 624 | "ACPI _SDD failed (AE 0x%x)\n", status); |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 625 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 626 | return err; |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 629 | /** |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 630 | * ata_acpi_on_suspend - ATA ACPI hook called on suspend |
| 631 | * @ap: target ATA port |
| 632 | * |
| 633 | * This function is called when @ap is about to be suspended. All |
| 634 | * devices are already put to sleep but the port_suspend() callback |
| 635 | * hasn't been executed yet. Error return from this function aborts |
| 636 | * suspend. |
| 637 | * |
| 638 | * LOCKING: |
| 639 | * EH context. |
| 640 | * |
| 641 | * RETURNS: |
| 642 | * 0 on success, -errno on failure. |
| 643 | */ |
| 644 | int ata_acpi_on_suspend(struct ata_port *ap) |
| 645 | { |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 646 | /* nada */ |
| 647 | return 0; |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | /** |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 651 | * ata_acpi_on_resume - ATA ACPI hook called on resume |
| 652 | * @ap: target ATA port |
| 653 | * |
| 654 | * This function is called when @ap is resumed - right after port |
| 655 | * itself is resumed but before any EH action is taken. |
| 656 | * |
| 657 | * LOCKING: |
| 658 | * EH context. |
| 659 | */ |
| 660 | void ata_acpi_on_resume(struct ata_port *ap) |
| 661 | { |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 662 | const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 663 | struct ata_device *dev; |
Kristen Carlson Accardi | 7ea1fbc | 2006-09-28 11:29:12 -0700 | [diff] [blame] | 664 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 665 | if (ap->acpi_handle && gtm) { |
| 666 | /* _GTM valid */ |
| 667 | |
| 668 | /* restore timing parameters */ |
Tejun Heo | c05e6ff | 2007-12-15 15:05:02 +0900 | [diff] [blame] | 669 | ata_acpi_stm(ap, gtm); |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 670 | |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 671 | /* _GTF should immediately follow _STM so that it can |
| 672 | * use values set by _STM. Cache _GTF result and |
| 673 | * schedule _GTF. |
| 674 | */ |
| 675 | ata_link_for_each_dev(dev, &ap->link) { |
| 676 | ata_acpi_clear_gtf(dev); |
| 677 | if (ata_dev_get_GTF(dev, NULL) >= 0) |
| 678 | dev->flags |= ATA_DFLAG_ACPI_PENDING; |
| 679 | } |
| 680 | } else { |
| 681 | /* SATA _GTF needs to be evaulated after _SDD and |
| 682 | * there's no reason to evaluate IDE _GTF early |
| 683 | * without _STM. Clear cache and schedule _GTF. |
| 684 | */ |
| 685 | ata_link_for_each_dev(dev, &ap->link) { |
| 686 | ata_acpi_clear_gtf(dev); |
| 687 | dev->flags |= ATA_DFLAG_ACPI_PENDING; |
| 688 | } |
| 689 | } |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /** |
| 693 | * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration |
| 694 | * @dev: target ATA device |
| 695 | * |
| 696 | * This function is called when @dev is about to be configured. |
| 697 | * IDENTIFY data might have been modified after this hook is run. |
| 698 | * |
| 699 | * LOCKING: |
| 700 | * EH context. |
| 701 | * |
| 702 | * RETURNS: |
| 703 | * Positive number if IDENTIFY data needs to be refreshed, 0 if not, |
| 704 | * -errno on failure. |
| 705 | */ |
| 706 | int ata_acpi_on_devcfg(struct ata_device *dev) |
| 707 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 708 | struct ata_port *ap = dev->link->ap; |
| 709 | struct ata_eh_context *ehc = &ap->link.eh_context; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 710 | int acpi_sata = ap->flags & ATA_FLAG_ACPI_SATA; |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 711 | int nr_executed = 0; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 712 | int rc; |
| 713 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 714 | if (!dev->acpi_handle) |
| 715 | return 0; |
| 716 | |
| 717 | /* do we need to do _GTF? */ |
| 718 | if (!(dev->flags & ATA_DFLAG_ACPI_PENDING) && |
| 719 | !(acpi_sata && (ehc->i.flags & ATA_EHI_DID_HARDRESET))) |
| 720 | return 0; |
| 721 | |
| 722 | /* do _SDD if SATA */ |
| 723 | if (acpi_sata) { |
| 724 | rc = ata_acpi_push_id(dev); |
| 725 | if (rc) |
| 726 | goto acpi_err; |
| 727 | } |
| 728 | |
| 729 | /* do _GTF */ |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 730 | rc = ata_acpi_exec_tfs(dev, &nr_executed); |
| 731 | if (rc) |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 732 | goto acpi_err; |
| 733 | |
| 734 | dev->flags &= ~ATA_DFLAG_ACPI_PENDING; |
| 735 | |
| 736 | /* refresh IDENTIFY page if any _GTF command has been executed */ |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 737 | if (nr_executed) { |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 738 | rc = ata_dev_reread_id(dev, 0); |
| 739 | if (rc < 0) { |
| 740 | ata_dev_printk(dev, KERN_ERR, "failed to IDENTIFY " |
| 741 | "after ACPI commands\n"); |
| 742 | return rc; |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | return 0; |
| 747 | |
| 748 | acpi_err: |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 749 | /* ignore evaluation failure if we can continue safely */ |
| 750 | if (rc == -EINVAL && !nr_executed && !(ap->pflags & ATA_PFLAG_FROZEN)) |
| 751 | return 0; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 752 | |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 753 | /* fail and let EH retry once more for unknown IO errors */ |
| 754 | if (!(dev->flags & ATA_DFLAG_ACPI_FAILED)) { |
| 755 | dev->flags |= ATA_DFLAG_ACPI_FAILED; |
| 756 | return rc; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 757 | } |
Tejun Heo | 66fa7f2 | 2007-12-15 15:05:04 +0900 | [diff] [blame^] | 758 | |
| 759 | ata_dev_printk(dev, KERN_WARNING, |
| 760 | "ACPI: failed the second time, disabled\n"); |
| 761 | dev->acpi_handle = NULL; |
| 762 | |
| 763 | /* We can safely continue if no _GTF command has been executed |
| 764 | * and port is not frozen. |
| 765 | */ |
| 766 | if (!nr_executed && !(ap->pflags & ATA_PFLAG_FROZEN)) |
| 767 | return 0; |
| 768 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 769 | return rc; |
| 770 | } |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 771 | |
| 772 | /** |
| 773 | * ata_acpi_on_disable - ATA ACPI hook called when a device is disabled |
| 774 | * @dev: target ATA device |
| 775 | * |
| 776 | * This function is called when @dev is about to be disabled. |
| 777 | * |
| 778 | * LOCKING: |
| 779 | * EH context. |
| 780 | */ |
| 781 | void ata_acpi_on_disable(struct ata_device *dev) |
| 782 | { |
Tejun Heo | 398e078 | 2007-12-15 15:05:03 +0900 | [diff] [blame] | 783 | ata_acpi_clear_gtf(dev); |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 784 | } |