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