Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 1 | /* |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 2 | * Provides ACPI support for IDE drives. |
| 3 | * |
| 4 | * Copyright (C) 2005 Intel Corp. |
| 5 | * Copyright (C) 2005 Randy Dunlap |
| 6 | * Copyright (C) 2006 SUSE Linux Products GmbH |
| 7 | * Copyright (C) 2006 Hannes Reinecke |
| 8 | */ |
| 9 | |
| 10 | #include <linux/ata.h> |
| 11 | #include <linux/delay.h> |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <acpi/acpi.h> |
| 16 | #include <linux/ide.h> |
| 17 | #include <linux/pci.h> |
Shaohua Li | 9049489 | 2008-01-10 23:03:42 +0100 | [diff] [blame] | 18 | #include <linux/dmi.h> |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 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 | |
| 28 | #define REGS_PER_GTF 7 |
| 29 | struct taskfile_array { |
| 30 | u8 tfa[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */ |
| 31 | }; |
| 32 | |
| 33 | struct GTM_buffer { |
| 34 | u32 PIO_speed0; |
| 35 | u32 DMA_speed0; |
| 36 | u32 PIO_speed1; |
| 37 | u32 DMA_speed1; |
| 38 | u32 GTM_flags; |
| 39 | }; |
| 40 | |
| 41 | struct ide_acpi_drive_link { |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 42 | acpi_handle obj_handle; |
| 43 | u8 idbuff[512]; |
| 44 | }; |
| 45 | |
| 46 | struct ide_acpi_hwif_link { |
| 47 | ide_hwif_t *hwif; |
| 48 | acpi_handle obj_handle; |
| 49 | struct GTM_buffer gtm; |
| 50 | struct ide_acpi_drive_link master; |
| 51 | struct ide_acpi_drive_link slave; |
| 52 | }; |
| 53 | |
| 54 | #undef DEBUGGING |
| 55 | /* note: adds function name and KERN_DEBUG */ |
| 56 | #ifdef DEBUGGING |
| 57 | #define DEBPRINT(fmt, args...) \ |
Harvey Harrison | eb63963 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 58 | printk(KERN_DEBUG "%s: " fmt, __func__, ## args) |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 59 | #else |
| 60 | #define DEBPRINT(fmt, args...) do {} while (0) |
| 61 | #endif /* DEBUGGING */ |
| 62 | |
Bartlomiej Zolnierkiewicz | 931ee0d | 2008-07-15 21:21:47 +0200 | [diff] [blame] | 63 | static int ide_noacpi; |
Bartlomiej Zolnierkiewicz | 1dbfeb4 | 2008-04-27 15:38:30 +0200 | [diff] [blame] | 64 | module_param_named(noacpi, ide_noacpi, bool, 0); |
| 65 | MODULE_PARM_DESC(noacpi, "disable IDE ACPI support"); |
| 66 | |
Bartlomiej Zolnierkiewicz | 931ee0d | 2008-07-15 21:21:47 +0200 | [diff] [blame] | 67 | static int ide_acpigtf; |
Bartlomiej Zolnierkiewicz | 1dbfeb4 | 2008-04-27 15:38:30 +0200 | [diff] [blame] | 68 | module_param_named(acpigtf, ide_acpigtf, bool, 0); |
| 69 | MODULE_PARM_DESC(acpigtf, "enable IDE ACPI _GTF support"); |
| 70 | |
Bartlomiej Zolnierkiewicz | 931ee0d | 2008-07-15 21:21:47 +0200 | [diff] [blame] | 71 | static int ide_acpionboot; |
Bartlomiej Zolnierkiewicz | 1dbfeb4 | 2008-04-27 15:38:30 +0200 | [diff] [blame] | 72 | module_param_named(acpionboot, ide_acpionboot, bool, 0); |
| 73 | MODULE_PARM_DESC(acpionboot, "call IDE ACPI methods on boot"); |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 74 | |
Shaohua Li | 9049489 | 2008-01-10 23:03:42 +0100 | [diff] [blame] | 75 | static bool ide_noacpi_psx; |
| 76 | static int no_acpi_psx(const struct dmi_system_id *id) |
| 77 | { |
| 78 | ide_noacpi_psx = true; |
| 79 | printk(KERN_NOTICE"%s detected - disable ACPI _PSx.\n", id->ident); |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static const struct dmi_system_id ide_acpi_dmi_table[] = { |
| 84 | /* Bug 9673. */ |
| 85 | /* We should check if this is because ACPI NVS isn't save/restored. */ |
| 86 | { |
| 87 | .callback = no_acpi_psx, |
| 88 | .ident = "HP nx9005", |
| 89 | .matches = { |
| 90 | DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies Ltd."), |
| 91 | DMI_MATCH(DMI_BIOS_VERSION, "KAM1.60") |
| 92 | }, |
| 93 | }, |
Jeff Garzik | 7c48c56 | 2008-01-10 23:59:18 -0500 | [diff] [blame] | 94 | |
| 95 | { } /* terminate list */ |
Shaohua Li | 9049489 | 2008-01-10 23:03:42 +0100 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | static int ide_acpi_blacklist(void) |
| 99 | { |
| 100 | static int done; |
| 101 | if (done) |
| 102 | return 0; |
| 103 | done = 1; |
| 104 | dmi_check_system(ide_acpi_dmi_table); |
| 105 | return 0; |
| 106 | } |
| 107 | |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 108 | /** |
| 109 | * ide_get_dev_handle - finds acpi_handle and PCI device.function |
| 110 | * @dev: device to locate |
| 111 | * @handle: returned acpi_handle for @dev |
| 112 | * @pcidevfn: return PCI device.func for @dev |
| 113 | * |
| 114 | * Returns the ACPI object handle to the corresponding PCI device. |
| 115 | * |
| 116 | * Returns 0 on success, <0 on error. |
| 117 | */ |
| 118 | static int ide_get_dev_handle(struct device *dev, acpi_handle *handle, |
| 119 | acpi_integer *pcidevfn) |
| 120 | { |
| 121 | struct pci_dev *pdev = to_pci_dev(dev); |
| 122 | unsigned int bus, devnum, func; |
| 123 | acpi_integer addr; |
| 124 | acpi_handle dev_handle; |
| 125 | struct acpi_buffer buffer = {.length = ACPI_ALLOCATE_BUFFER, |
| 126 | .pointer = NULL}; |
| 127 | acpi_status status; |
| 128 | struct acpi_device_info *dinfo = NULL; |
| 129 | int ret = -ENODEV; |
| 130 | |
| 131 | bus = pdev->bus->number; |
| 132 | devnum = PCI_SLOT(pdev->devfn); |
| 133 | func = PCI_FUNC(pdev->devfn); |
| 134 | /* ACPI _ADR encoding for PCI bus: */ |
| 135 | addr = (acpi_integer)(devnum << 16 | func); |
| 136 | |
| 137 | DEBPRINT("ENTER: pci %02x:%02x.%01x\n", bus, devnum, func); |
| 138 | |
| 139 | dev_handle = DEVICE_ACPI_HANDLE(dev); |
| 140 | if (!dev_handle) { |
| 141 | DEBPRINT("no acpi handle for device\n"); |
| 142 | goto err; |
| 143 | } |
| 144 | |
| 145 | status = acpi_get_object_info(dev_handle, &buffer); |
| 146 | if (ACPI_FAILURE(status)) { |
| 147 | DEBPRINT("get_object_info for device failed\n"); |
| 148 | goto err; |
| 149 | } |
| 150 | dinfo = buffer.pointer; |
| 151 | if (dinfo && (dinfo->valid & ACPI_VALID_ADR) && |
| 152 | dinfo->address == addr) { |
| 153 | *pcidevfn = addr; |
| 154 | *handle = dev_handle; |
| 155 | } else { |
| 156 | DEBPRINT("get_object_info for device has wrong " |
| 157 | " address: %llu, should be %u\n", |
| 158 | dinfo ? (unsigned long long)dinfo->address : -1ULL, |
| 159 | (unsigned int)addr); |
| 160 | goto err; |
| 161 | } |
| 162 | |
| 163 | DEBPRINT("for dev=0x%x.%x, addr=0x%llx, *handle=0x%p\n", |
| 164 | devnum, func, (unsigned long long)addr, *handle); |
| 165 | ret = 0; |
| 166 | err: |
| 167 | kfree(dinfo); |
| 168 | return ret; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * ide_acpi_hwif_get_handle - Get ACPI object handle for a given hwif |
| 173 | * @hwif: device to locate |
| 174 | * |
| 175 | * Retrieves the object handle for a given hwif. |
| 176 | * |
| 177 | * Returns handle on success, 0 on error. |
| 178 | */ |
| 179 | static acpi_handle ide_acpi_hwif_get_handle(ide_hwif_t *hwif) |
| 180 | { |
| 181 | struct device *dev = hwif->gendev.parent; |
Andrew Morton | 1dcfdf9 | 2008-02-06 02:57:49 +0100 | [diff] [blame] | 182 | acpi_handle uninitialized_var(dev_handle); |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 183 | acpi_integer pcidevfn; |
| 184 | acpi_handle chan_handle; |
| 185 | int err; |
| 186 | |
| 187 | DEBPRINT("ENTER: device %s\n", hwif->name); |
| 188 | |
| 189 | if (!dev) { |
| 190 | DEBPRINT("no PCI device for %s\n", hwif->name); |
| 191 | return NULL; |
| 192 | } |
| 193 | |
| 194 | err = ide_get_dev_handle(dev, &dev_handle, &pcidevfn); |
| 195 | if (err < 0) { |
| 196 | DEBPRINT("ide_get_dev_handle failed (%d)\n", err); |
| 197 | return NULL; |
| 198 | } |
| 199 | |
| 200 | /* get child objects of dev_handle == channel objects, |
| 201 | * + _their_ children == drive objects */ |
| 202 | /* channel is hwif->channel */ |
| 203 | chan_handle = acpi_get_child(dev_handle, hwif->channel); |
| 204 | DEBPRINT("chan adr=%d: handle=0x%p\n", |
| 205 | hwif->channel, chan_handle); |
| 206 | |
| 207 | return chan_handle; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * ide_acpi_drive_get_handle - Get ACPI object handle for a given drive |
| 212 | * @drive: device to locate |
| 213 | * |
| 214 | * Retrieves the object handle of a given drive. According to the ACPI |
| 215 | * spec the drive is a child of the hwif. |
| 216 | * |
| 217 | * Returns handle on success, 0 on error. |
| 218 | */ |
| 219 | static acpi_handle ide_acpi_drive_get_handle(ide_drive_t *drive) |
| 220 | { |
Bartlomiej Zolnierkiewicz | 898ec22 | 2009-01-06 17:20:52 +0100 | [diff] [blame^] | 221 | ide_hwif_t *hwif = drive->hwif; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 222 | int port; |
| 223 | acpi_handle drive_handle; |
| 224 | |
| 225 | if (!hwif->acpidata) |
| 226 | return NULL; |
| 227 | |
| 228 | if (!hwif->acpidata->obj_handle) |
| 229 | return NULL; |
| 230 | |
| 231 | port = hwif->channel ? drive->dn - 2: drive->dn; |
| 232 | |
| 233 | DEBPRINT("ENTER: %s at channel#: %d port#: %d\n", |
| 234 | drive->name, hwif->channel, port); |
| 235 | |
| 236 | |
| 237 | /* TBD: could also check ACPI object VALID bits */ |
| 238 | drive_handle = acpi_get_child(hwif->acpidata->obj_handle, port); |
| 239 | DEBPRINT("drive %s handle 0x%p\n", drive->name, drive_handle); |
| 240 | |
| 241 | return drive_handle; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * do_drive_get_GTF - get the drive bootup default taskfile settings |
| 246 | * @drive: the drive for which the taskfile settings should be retrieved |
| 247 | * @gtf_length: number of bytes of _GTF data returned at @gtf_address |
| 248 | * @gtf_address: buffer containing _GTF taskfile arrays |
| 249 | * |
| 250 | * The _GTF method has no input parameters. |
| 251 | * It returns a variable number of register set values (registers |
| 252 | * hex 1F1..1F7, taskfiles). |
| 253 | * The <variable number> is not known in advance, so have ACPI-CA |
| 254 | * allocate the buffer as needed and return it, then free it later. |
| 255 | * |
| 256 | * The returned @gtf_length and @gtf_address are only valid if the |
| 257 | * function return value is 0. |
| 258 | */ |
| 259 | static int do_drive_get_GTF(ide_drive_t *drive, |
| 260 | unsigned int *gtf_length, unsigned long *gtf_address, |
| 261 | unsigned long *obj_loc) |
| 262 | { |
| 263 | acpi_status status; |
| 264 | struct acpi_buffer output; |
| 265 | union acpi_object *out_obj; |
Bartlomiej Zolnierkiewicz | 898ec22 | 2009-01-06 17:20:52 +0100 | [diff] [blame^] | 266 | ide_hwif_t *hwif = drive->hwif; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 267 | struct device *dev = hwif->gendev.parent; |
| 268 | int err = -ENODEV; |
| 269 | int port; |
| 270 | |
| 271 | *gtf_length = 0; |
| 272 | *gtf_address = 0UL; |
| 273 | *obj_loc = 0UL; |
| 274 | |
| 275 | if (ide_noacpi) |
| 276 | return 0; |
| 277 | |
| 278 | if (!dev) { |
| 279 | DEBPRINT("no PCI device for %s\n", hwif->name); |
| 280 | goto out; |
| 281 | } |
| 282 | |
| 283 | if (!hwif->acpidata) { |
| 284 | DEBPRINT("no ACPI data for %s\n", hwif->name); |
| 285 | goto out; |
| 286 | } |
| 287 | |
| 288 | port = hwif->channel ? drive->dn - 2: drive->dn; |
| 289 | |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 290 | DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n", |
| 291 | hwif->name, dev->bus_id, port, hwif->channel); |
| 292 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 293 | if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) { |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 294 | DEBPRINT("%s drive %d:%d not present\n", |
| 295 | hwif->name, hwif->channel, port); |
| 296 | goto out; |
| 297 | } |
| 298 | |
| 299 | /* Get this drive's _ADR info. if not already known. */ |
| 300 | if (!drive->acpidata->obj_handle) { |
| 301 | drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive); |
| 302 | if (!drive->acpidata->obj_handle) { |
| 303 | DEBPRINT("No ACPI object found for %s\n", |
| 304 | drive->name); |
| 305 | goto out; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /* Setting up output buffer */ |
| 310 | output.length = ACPI_ALLOCATE_BUFFER; |
| 311 | output.pointer = NULL; /* ACPI-CA sets this; save/free it later */ |
| 312 | |
| 313 | /* _GTF has no input parameters */ |
| 314 | err = -EIO; |
| 315 | status = acpi_evaluate_object(drive->acpidata->obj_handle, "_GTF", |
| 316 | NULL, &output); |
| 317 | if (ACPI_FAILURE(status)) { |
| 318 | printk(KERN_DEBUG |
| 319 | "%s: Run _GTF error: status = 0x%x\n", |
Harvey Harrison | eb63963 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 320 | __func__, status); |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 321 | goto out; |
| 322 | } |
| 323 | |
| 324 | if (!output.length || !output.pointer) { |
| 325 | DEBPRINT("Run _GTF: " |
| 326 | "length or ptr is NULL (0x%llx, 0x%p)\n", |
| 327 | (unsigned long long)output.length, |
| 328 | output.pointer); |
| 329 | goto out; |
| 330 | } |
| 331 | |
| 332 | out_obj = output.pointer; |
| 333 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
| 334 | DEBPRINT("Run _GTF: error: " |
| 335 | "expected object type of ACPI_TYPE_BUFFER, " |
| 336 | "got 0x%x\n", out_obj->type); |
| 337 | err = -ENOENT; |
| 338 | kfree(output.pointer); |
| 339 | goto out; |
| 340 | } |
| 341 | |
| 342 | if (!out_obj->buffer.length || !out_obj->buffer.pointer || |
| 343 | out_obj->buffer.length % REGS_PER_GTF) { |
| 344 | printk(KERN_ERR |
| 345 | "%s: unexpected GTF length (%d) or addr (0x%p)\n", |
Harvey Harrison | eb63963 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 346 | __func__, out_obj->buffer.length, |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 347 | out_obj->buffer.pointer); |
| 348 | err = -ENOENT; |
| 349 | kfree(output.pointer); |
| 350 | goto out; |
| 351 | } |
| 352 | |
| 353 | *gtf_length = out_obj->buffer.length; |
| 354 | *gtf_address = (unsigned long)out_obj->buffer.pointer; |
| 355 | *obj_loc = (unsigned long)out_obj; |
| 356 | DEBPRINT("returning gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n", |
| 357 | *gtf_length, *gtf_address, *obj_loc); |
| 358 | err = 0; |
| 359 | out: |
| 360 | return err; |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * taskfile_load_raw - send taskfile registers to drive |
| 365 | * @drive: drive to which output is sent |
| 366 | * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7) |
| 367 | * |
| 368 | * Outputs IDE taskfile to the drive. |
| 369 | */ |
| 370 | static int taskfile_load_raw(ide_drive_t *drive, |
| 371 | const struct taskfile_array *gtf) |
| 372 | { |
| 373 | ide_task_t args; |
| 374 | int err = 0; |
| 375 | |
| 376 | DEBPRINT("(0x1f1-1f7): hex: " |
| 377 | "%02x %02x %02x %02x %02x %02x %02x\n", |
| 378 | gtf->tfa[0], gtf->tfa[1], gtf->tfa[2], |
| 379 | gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]); |
| 380 | |
| 381 | memset(&args, 0, sizeof(ide_task_t)); |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 382 | |
| 383 | /* convert gtf to IDE Taskfile */ |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 384 | memcpy(&args.tf_array[7], >f->tfa, 7); |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 385 | args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 386 | |
Bartlomiej Zolnierkiewicz | 1dbfeb4 | 2008-04-27 15:38:30 +0200 | [diff] [blame] | 387 | if (!ide_acpigtf) { |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 388 | DEBPRINT("_GTF execution disabled\n"); |
| 389 | return err; |
| 390 | } |
| 391 | |
Bartlomiej Zolnierkiewicz | 9a3c49b | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 392 | err = ide_no_data_taskfile(drive, &args); |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 393 | if (err) |
Bartlomiej Zolnierkiewicz | 9a3c49b | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 394 | printk(KERN_ERR "%s: ide_no_data_taskfile failed: %u\n", |
Harvey Harrison | eb63963 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 395 | __func__, err); |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 396 | |
| 397 | return err; |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * do_drive_set_taskfiles - write the drive taskfile settings from _GTF |
| 402 | * @drive: the drive to which the taskfile command should be sent |
| 403 | * @gtf_length: total number of bytes of _GTF taskfiles |
| 404 | * @gtf_address: location of _GTF taskfile arrays |
| 405 | * |
| 406 | * Write {gtf_address, length gtf_length} in groups of |
| 407 | * REGS_PER_GTF bytes. |
| 408 | */ |
| 409 | static int do_drive_set_taskfiles(ide_drive_t *drive, |
| 410 | unsigned int gtf_length, |
| 411 | unsigned long gtf_address) |
| 412 | { |
| 413 | int rc = -ENODEV, err; |
| 414 | int gtf_count = gtf_length / REGS_PER_GTF; |
| 415 | int ix; |
| 416 | struct taskfile_array *gtf; |
| 417 | |
| 418 | if (ide_noacpi) |
| 419 | return 0; |
| 420 | |
| 421 | DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn); |
| 422 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 423 | if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 424 | goto out; |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 425 | |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 426 | if (!gtf_count) /* shouldn't be here */ |
| 427 | goto out; |
| 428 | |
| 429 | DEBPRINT("total GTF bytes=%u (0x%x), gtf_count=%d, addr=0x%lx\n", |
| 430 | gtf_length, gtf_length, gtf_count, gtf_address); |
| 431 | |
| 432 | if (gtf_length % REGS_PER_GTF) { |
| 433 | printk(KERN_ERR "%s: unexpected GTF length (%d)\n", |
Harvey Harrison | eb63963 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 434 | __func__, gtf_length); |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 435 | goto out; |
| 436 | } |
| 437 | |
| 438 | rc = 0; |
| 439 | for (ix = 0; ix < gtf_count; ix++) { |
| 440 | gtf = (struct taskfile_array *) |
| 441 | (gtf_address + ix * REGS_PER_GTF); |
| 442 | |
| 443 | /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */ |
| 444 | err = taskfile_load_raw(drive, gtf); |
| 445 | if (err) |
| 446 | rc = err; |
| 447 | } |
| 448 | |
| 449 | out: |
| 450 | return rc; |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * ide_acpi_exec_tfs - get then write drive taskfile settings |
| 455 | * @drive: the drive for which the taskfile settings should be |
| 456 | * written. |
| 457 | * |
| 458 | * According to the ACPI spec this should be called after _STM |
| 459 | * has been evaluated for the interface. Some ACPI vendors interpret |
| 460 | * that as a hard requirement and modify the taskfile according |
| 461 | * to the Identify Drive information passed down with _STM. |
| 462 | * So one should really make sure to call this only after _STM has |
| 463 | * been executed. |
| 464 | */ |
| 465 | int ide_acpi_exec_tfs(ide_drive_t *drive) |
| 466 | { |
| 467 | int ret; |
| 468 | unsigned int gtf_length; |
| 469 | unsigned long gtf_address; |
| 470 | unsigned long obj_loc; |
| 471 | |
| 472 | if (ide_noacpi) |
| 473 | return 0; |
| 474 | |
| 475 | DEBPRINT("call get_GTF, drive=%s port=%d\n", drive->name, drive->dn); |
| 476 | |
| 477 | ret = do_drive_get_GTF(drive, >f_length, >f_address, &obj_loc); |
| 478 | if (ret < 0) { |
| 479 | DEBPRINT("get_GTF error (%d)\n", ret); |
| 480 | return ret; |
| 481 | } |
| 482 | |
| 483 | DEBPRINT("call set_taskfiles, drive=%s\n", drive->name); |
| 484 | |
| 485 | ret = do_drive_set_taskfiles(drive, gtf_length, gtf_address); |
| 486 | kfree((void *)obj_loc); |
| 487 | if (ret < 0) { |
| 488 | DEBPRINT("set_taskfiles error (%d)\n", ret); |
| 489 | } |
| 490 | |
| 491 | DEBPRINT("ret=%d\n", ret); |
| 492 | |
| 493 | return ret; |
| 494 | } |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 495 | |
| 496 | /** |
| 497 | * ide_acpi_get_timing - get the channel (controller) timings |
| 498 | * @hwif: target IDE interface (channel) |
| 499 | * |
| 500 | * This function executes the _GTM ACPI method for the target channel. |
| 501 | * |
| 502 | */ |
| 503 | void ide_acpi_get_timing(ide_hwif_t *hwif) |
| 504 | { |
| 505 | acpi_status status; |
| 506 | struct acpi_buffer output; |
| 507 | union acpi_object *out_obj; |
| 508 | |
| 509 | if (ide_noacpi) |
| 510 | return; |
| 511 | |
| 512 | DEBPRINT("ENTER:\n"); |
| 513 | |
| 514 | if (!hwif->acpidata) { |
| 515 | DEBPRINT("no ACPI data for %s\n", hwif->name); |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | /* Setting up output buffer for _GTM */ |
| 520 | output.length = ACPI_ALLOCATE_BUFFER; |
| 521 | output.pointer = NULL; /* ACPI-CA sets this; save/free it later */ |
| 522 | |
| 523 | /* _GTM has no input parameters */ |
| 524 | status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_GTM", |
| 525 | NULL, &output); |
| 526 | |
| 527 | DEBPRINT("_GTM status: %d, outptr: 0x%p, outlen: 0x%llx\n", |
| 528 | status, output.pointer, |
| 529 | (unsigned long long)output.length); |
| 530 | |
| 531 | if (ACPI_FAILURE(status)) { |
| 532 | DEBPRINT("Run _GTM error: status = 0x%x\n", status); |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | if (!output.length || !output.pointer) { |
| 537 | DEBPRINT("Run _GTM: length or ptr is NULL (0x%llx, 0x%p)\n", |
| 538 | (unsigned long long)output.length, |
| 539 | output.pointer); |
| 540 | kfree(output.pointer); |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | out_obj = output.pointer; |
| 545 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
| 546 | kfree(output.pointer); |
| 547 | DEBPRINT("Run _GTM: error: " |
| 548 | "expected object type of ACPI_TYPE_BUFFER, " |
| 549 | "got 0x%x\n", out_obj->type); |
| 550 | return; |
| 551 | } |
| 552 | |
| 553 | if (!out_obj->buffer.length || !out_obj->buffer.pointer || |
| 554 | out_obj->buffer.length != sizeof(struct GTM_buffer)) { |
| 555 | kfree(output.pointer); |
| 556 | printk(KERN_ERR |
Andrew Morton | 1e8f34f | 2007-02-07 18:19:42 +0100 | [diff] [blame] | 557 | "%s: unexpected _GTM length (0x%x)[should be 0x%zx] or " |
| 558 | "addr (0x%p)\n", |
Harvey Harrison | eb63963 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 559 | __func__, out_obj->buffer.length, |
Andrew Morton | 1e8f34f | 2007-02-07 18:19:42 +0100 | [diff] [blame] | 560 | sizeof(struct GTM_buffer), out_obj->buffer.pointer); |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 561 | return; |
| 562 | } |
| 563 | |
| 564 | memcpy(&hwif->acpidata->gtm, out_obj->buffer.pointer, |
| 565 | sizeof(struct GTM_buffer)); |
| 566 | |
| 567 | DEBPRINT("_GTM info: ptr: 0x%p, len: 0x%x, exp.len: 0x%Zx\n", |
| 568 | out_obj->buffer.pointer, out_obj->buffer.length, |
| 569 | sizeof(struct GTM_buffer)); |
| 570 | |
| 571 | DEBPRINT("_GTM fields: 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", |
| 572 | hwif->acpidata->gtm.PIO_speed0, |
| 573 | hwif->acpidata->gtm.DMA_speed0, |
| 574 | hwif->acpidata->gtm.PIO_speed1, |
| 575 | hwif->acpidata->gtm.DMA_speed1, |
| 576 | hwif->acpidata->gtm.GTM_flags); |
| 577 | |
| 578 | kfree(output.pointer); |
| 579 | } |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 580 | |
| 581 | /** |
| 582 | * ide_acpi_push_timing - set the channel (controller) timings |
| 583 | * @hwif: target IDE interface (channel) |
| 584 | * |
| 585 | * This function executes the _STM ACPI method for the target channel. |
| 586 | * |
| 587 | * _STM requires Identify Drive data, which has to passed as an argument. |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 588 | * Unfortunately drive->id is a mangled version which we can't readily |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 589 | * use; hence we'll get the information afresh. |
| 590 | */ |
| 591 | void ide_acpi_push_timing(ide_hwif_t *hwif) |
| 592 | { |
| 593 | acpi_status status; |
| 594 | struct acpi_object_list input; |
| 595 | union acpi_object in_params[3]; |
| 596 | struct ide_acpi_drive_link *master = &hwif->acpidata->master; |
| 597 | struct ide_acpi_drive_link *slave = &hwif->acpidata->slave; |
| 598 | |
| 599 | if (ide_noacpi) |
| 600 | return; |
| 601 | |
| 602 | DEBPRINT("ENTER:\n"); |
| 603 | |
| 604 | if (!hwif->acpidata) { |
| 605 | DEBPRINT("no ACPI data for %s\n", hwif->name); |
| 606 | return; |
| 607 | } |
| 608 | |
| 609 | /* Give the GTM buffer + drive Identify data to the channel via the |
| 610 | * _STM method: */ |
| 611 | /* setup input parameters buffer for _STM */ |
| 612 | input.count = 3; |
| 613 | input.pointer = in_params; |
| 614 | in_params[0].type = ACPI_TYPE_BUFFER; |
| 615 | in_params[0].buffer.length = sizeof(struct GTM_buffer); |
| 616 | in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm; |
| 617 | in_params[1].type = ACPI_TYPE_BUFFER; |
Bartlomiej Zolnierkiewicz | 0e63a58 | 2008-12-29 20:27:29 +0100 | [diff] [blame] | 618 | in_params[1].buffer.length = ATA_ID_WORDS * 2; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 619 | in_params[1].buffer.pointer = (u8 *)&master->idbuff; |
| 620 | in_params[2].type = ACPI_TYPE_BUFFER; |
Bartlomiej Zolnierkiewicz | 0e63a58 | 2008-12-29 20:27:29 +0100 | [diff] [blame] | 621 | in_params[2].buffer.length = ATA_ID_WORDS * 2; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 622 | in_params[2].buffer.pointer = (u8 *)&slave->idbuff; |
| 623 | /* Output buffer: _STM has no output */ |
| 624 | |
| 625 | status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_STM", |
| 626 | &input, NULL); |
| 627 | |
| 628 | if (ACPI_FAILURE(status)) { |
| 629 | DEBPRINT("Run _STM error: status = 0x%x\n", status); |
| 630 | } |
| 631 | DEBPRINT("_STM status: %d\n", status); |
| 632 | } |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 633 | |
| 634 | /** |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 635 | * ide_acpi_set_state - set the channel power state |
| 636 | * @hwif: target IDE interface |
| 637 | * @on: state, on/off |
| 638 | * |
| 639 | * This function executes the _PS0/_PS3 ACPI method to set the power state. |
| 640 | * ACPI spec requires _PS0 when IDE power on and _PS3 when power off |
| 641 | */ |
| 642 | void ide_acpi_set_state(ide_hwif_t *hwif, int on) |
| 643 | { |
| 644 | int unit; |
| 645 | |
Shaohua Li | 9049489 | 2008-01-10 23:03:42 +0100 | [diff] [blame] | 646 | if (ide_noacpi || ide_noacpi_psx) |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 647 | return; |
| 648 | |
| 649 | DEBPRINT("ENTER:\n"); |
| 650 | |
| 651 | if (!hwif->acpidata) { |
| 652 | DEBPRINT("no ACPI data for %s\n", hwif->name); |
| 653 | return; |
| 654 | } |
| 655 | /* channel first and then drives for power on and verse versa for power off */ |
| 656 | if (on) |
| 657 | acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0); |
| 658 | for (unit = 0; unit < MAX_DRIVES; ++unit) { |
| 659 | ide_drive_t *drive = &hwif->drives[unit]; |
| 660 | |
| 661 | if (!drive->acpidata->obj_handle) |
| 662 | drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive); |
| 663 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 664 | if (drive->acpidata->obj_handle && |
| 665 | (drive->dev_flags & IDE_DFLAG_PRESENT)) { |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 666 | acpi_bus_set_power(drive->acpidata->obj_handle, |
| 667 | on? ACPI_STATE_D0: ACPI_STATE_D3); |
| 668 | } |
| 669 | } |
| 670 | if (!on) |
| 671 | acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D3); |
| 672 | } |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 673 | |
| 674 | /** |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 675 | * ide_acpi_init - initialize the ACPI link for an IDE interface |
| 676 | * @hwif: target IDE interface (channel) |
| 677 | * |
| 678 | * The ACPI spec is not quite clear when the drive identify buffer |
| 679 | * should be obtained. Calling IDENTIFY DEVICE during shutdown |
| 680 | * is not the best of ideas as the drive might already being put to |
| 681 | * sleep. And obviously we can't call it during resume. |
| 682 | * So we get the information during startup; but this means that |
| 683 | * any changes during run-time will be lost after resume. |
| 684 | */ |
| 685 | void ide_acpi_init(ide_hwif_t *hwif) |
| 686 | { |
Shaohua Li | 9049489 | 2008-01-10 23:03:42 +0100 | [diff] [blame] | 687 | ide_acpi_blacklist(); |
| 688 | |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 689 | hwif->acpidata = kzalloc(sizeof(struct ide_acpi_hwif_link), GFP_KERNEL); |
| 690 | if (!hwif->acpidata) |
| 691 | return; |
| 692 | |
| 693 | hwif->acpidata->obj_handle = ide_acpi_hwif_get_handle(hwif); |
| 694 | if (!hwif->acpidata->obj_handle) { |
| 695 | DEBPRINT("no ACPI object for %s found\n", hwif->name); |
| 696 | kfree(hwif->acpidata); |
| 697 | hwif->acpidata = NULL; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 698 | } |
Bartlomiej Zolnierkiewicz | eafd88a | 2008-02-02 19:56:43 +0100 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | void ide_acpi_port_init_devices(ide_hwif_t *hwif) |
| 702 | { |
| 703 | ide_drive_t *drive; |
| 704 | int i, err; |
| 705 | |
| 706 | if (hwif->acpidata == NULL) |
| 707 | return; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 708 | |
| 709 | /* |
| 710 | * The ACPI spec mandates that we send information |
| 711 | * for both drives, regardless whether they are connected |
| 712 | * or not. |
| 713 | */ |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 714 | hwif->drives[0].acpidata = &hwif->acpidata->master; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 715 | hwif->drives[1].acpidata = &hwif->acpidata->slave; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 716 | |
| 717 | /* |
| 718 | * Send IDENTIFY for each drive |
| 719 | */ |
Bartlomiej Zolnierkiewicz | eafd88a | 2008-02-02 19:56:43 +0100 | [diff] [blame] | 720 | for (i = 0; i < MAX_DRIVES; i++) { |
| 721 | drive = &hwif->drives[i]; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 722 | |
Bartlomiej Zolnierkiewicz | 8f22a72 | 2008-04-18 00:46:21 +0200 | [diff] [blame] | 723 | memset(drive->acpidata, 0, sizeof(*drive->acpidata)); |
| 724 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 725 | if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) |
Bartlomiej Zolnierkiewicz | eafd88a | 2008-02-02 19:56:43 +0100 | [diff] [blame] | 726 | continue; |
| 727 | |
| 728 | err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff); |
| 729 | if (err) |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 730 | DEBPRINT("identify device %s failed (%d)\n", |
Bartlomiej Zolnierkiewicz | eafd88a | 2008-02-02 19:56:43 +0100 | [diff] [blame] | 731 | drive->name, err); |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 732 | } |
| 733 | |
Bartlomiej Zolnierkiewicz | 1dbfeb4 | 2008-04-27 15:38:30 +0200 | [diff] [blame] | 734 | if (!ide_acpionboot) { |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 735 | DEBPRINT("ACPI methods disabled on boot\n"); |
| 736 | return; |
| 737 | } |
| 738 | |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 739 | /* ACPI _PS0 before _STM */ |
| 740 | ide_acpi_set_state(hwif, 1); |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 741 | /* |
| 742 | * ACPI requires us to call _STM on startup |
| 743 | */ |
| 744 | ide_acpi_get_timing(hwif); |
| 745 | ide_acpi_push_timing(hwif); |
| 746 | |
Bartlomiej Zolnierkiewicz | eafd88a | 2008-02-02 19:56:43 +0100 | [diff] [blame] | 747 | for (i = 0; i < MAX_DRIVES; i++) { |
| 748 | drive = &hwif->drives[i]; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 749 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 750 | if (drive->dev_flags & IDE_DFLAG_PRESENT) |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 751 | /* Execute ACPI startup code */ |
| 752 | ide_acpi_exec_tfs(drive); |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 753 | } |
| 754 | } |