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