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