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