|
Line 0
Link Here
|
|
|
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> |
| 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 { |
| 42 |
ide_drive_t *drive; |
| 43 |
acpi_handle obj_handle; |
| 44 |
u8 idbuff[512]; |
| 45 |
}; |
| 46 |
|
| 47 |
struct ide_acpi_hwif_link { |
| 48 |
ide_hwif_t *hwif; |
| 49 |
acpi_handle obj_handle; |
| 50 |
struct GTM_buffer gtm; |
| 51 |
struct ide_acpi_drive_link master; |
| 52 |
struct ide_acpi_drive_link slave; |
| 53 |
}; |
| 54 |
|
| 55 |
#define DEBUGGING 1 |
| 56 |
/* note: adds function name and KERN_DEBUG */ |
| 57 |
#ifdef DEBUGGING |
| 58 |
#define DEBPRINT(fmt, args...) \ |
| 59 |
printk(KERN_DEBUG "%s: " fmt, __FUNCTION__, ## args) |
| 60 |
#else |
| 61 |
#define DEBPRINT(fmt, args...) do {} while (0) |
| 62 |
#endif /* DEBUGGING */ |
| 63 |
|
| 64 |
extern int ide_noacpi; |
| 65 |
extern int ide_noacpitfs; |
| 66 |
|
| 67 |
/** |
| 68 |
* pata_get_dev_handle - finds acpi_handle and PCI device.function |
| 69 |
* @dev: device to locate |
| 70 |
* @handle: returned acpi_handle for @dev |
| 71 |
* @pcidevfn: return PCI device.func for @dev |
| 72 |
* |
| 73 |
* Returns the ACPI object handle to the corresponding PCI device. |
| 74 |
* |
| 75 |
* Returns 0 on success, <0 on error. |
| 76 |
*/ |
| 77 |
static int pata_get_dev_handle(struct device *dev, acpi_handle *handle, |
| 78 |
acpi_integer *pcidevfn) |
| 79 |
{ |
| 80 |
unsigned int domain, bus, devnum, func; |
| 81 |
acpi_integer addr; |
| 82 |
acpi_handle dev_handle, parent_handle; |
| 83 |
int scanned; |
| 84 |
struct acpi_buffer buffer = {.length = ACPI_ALLOCATE_BUFFER, |
| 85 |
.pointer = NULL}; |
| 86 |
acpi_status status; |
| 87 |
struct acpi_device_info *dinfo = NULL; |
| 88 |
int ret = -ENODEV; |
| 89 |
|
| 90 |
DEBPRINT("ENTER: dev->bus_id='%s'\n", dev->bus_id); |
| 91 |
|
| 92 |
if ((scanned = sscanf(dev->bus_id, "%x:%x:%x.%x", |
| 93 |
&domain, &bus, &devnum, &func)) != 4) { |
| 94 |
DEBPRINT("sscanf ret. %d\n", scanned); |
| 95 |
goto err; |
| 96 |
} |
| 97 |
|
| 98 |
dev_handle = DEVICE_ACPI_HANDLE(dev); |
| 99 |
parent_handle = DEVICE_ACPI_HANDLE(dev->parent); |
| 100 |
|
| 101 |
status = acpi_get_object_info(parent_handle, &buffer); |
| 102 |
if (ACPI_FAILURE(status)) { |
| 103 |
DEBPRINT("get_object_info for parent failed\n"); |
| 104 |
goto err; |
| 105 |
} |
| 106 |
dinfo = buffer.pointer; |
| 107 |
if (dinfo && (dinfo->valid & ACPI_VALID_ADR) && |
| 108 |
dinfo->address == bus) { |
| 109 |
/* ACPI spec for _ADR for PCI bus: */ |
| 110 |
addr = (acpi_integer)(devnum << 16 | func); |
| 111 |
*pcidevfn = addr; |
| 112 |
*handle = dev_handle; |
| 113 |
} else { |
| 114 |
DEBPRINT("get_object_info for parent has wrong " |
| 115 |
" bus: %llu, should be %d\n", |
| 116 |
dinfo ? (unsigned long long)dinfo->address : -1ULL, |
| 117 |
bus); |
| 118 |
goto err; |
| 119 |
} |
| 120 |
|
| 121 |
DEBPRINT("for dev=0x%x.%x, addr=0x%llx, parent=0x%p, *handle=0x%p\n", |
| 122 |
devnum, func, (unsigned long long)addr, |
| 123 |
dev->parent, *handle); |
| 124 |
if (!*handle) |
| 125 |
goto err; |
| 126 |
ret = 0; |
| 127 |
err: |
| 128 |
acpi_os_free(dinfo); |
| 129 |
return ret; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* ide_acpi_hwif_get_handle - Get ACPI object handle for a given hwif |
| 134 |
* @hwif: device to locate |
| 135 |
* |
| 136 |
* Retrieves the object handle of a given hwif. According to the ACPI |
| 137 |
* spec is the hwif a child of the PCI device. |
| 138 |
* |
| 139 |
* Returns handle on success, 0 on error. |
| 140 |
*/ |
| 141 |
acpi_handle ide_acpi_hwif_get_handle(ide_hwif_t *hwif) |
| 142 |
{ |
| 143 |
struct device *dev = hwif->gendev.parent; |
| 144 |
acpi_handle dev_handle; |
| 145 |
acpi_integer pcidevfn; |
| 146 |
acpi_handle chan_handle; |
| 147 |
int err; |
| 148 |
|
| 149 |
DEBPRINT("ENTER: device %s\n", hwif->name); |
| 150 |
|
| 151 |
if (!dev) { |
| 152 |
DEBPRINT("no PCI device for %s\n", hwif->name); |
| 153 |
return NULL; |
| 154 |
} |
| 155 |
|
| 156 |
err = pata_get_dev_handle(dev, &dev_handle, &pcidevfn); |
| 157 |
if (err < 0) { |
| 158 |
DEBPRINT("pata_get_dev_handle failed (%d)\n", err); |
| 159 |
return NULL; |
| 160 |
} |
| 161 |
|
| 162 |
/* get child objects of dev_handle == channel objects, |
| 163 |
* + _their_ children == drive objects */ |
| 164 |
/* channel is ap->hard_port_no */ |
| 165 |
chan_handle = acpi_get_child(dev_handle, hwif->channel); |
| 166 |
DEBPRINT("chan adr=%d: handle=0x%p\n", |
| 167 |
hwif->channel, chan_handle); |
| 168 |
|
| 169 |
return chan_handle; |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* ide_acpi_drive_get_handle - Get ACPI object handle for a given drive |
| 174 |
* @drive: device to locate |
| 175 |
* |
| 176 |
* Retrieves the object handle of a given drive. According to the ACPI |
| 177 |
* spec the drive is a child of the hwif. |
| 178 |
* |
| 179 |
* Returns handle on success, 0 on error. |
| 180 |
*/ |
| 181 |
acpi_handle ide_acpi_drive_get_handle(ide_drive_t *drive) |
| 182 |
{ |
| 183 |
ide_hwif_t *hwif = HWIF(drive); |
| 184 |
int port; |
| 185 |
acpi_handle drive_handle; |
| 186 |
|
| 187 |
if (!hwif->acpidata) |
| 188 |
return NULL; |
| 189 |
|
| 190 |
if (!hwif->acpidata->obj_handle) |
| 191 |
return NULL; |
| 192 |
|
| 193 |
port = hwif->channel ? drive->dn - 2: drive->dn; |
| 194 |
|
| 195 |
DEBPRINT("ENTER: %s at channel#: %d port#: %d\n", |
| 196 |
drive->name, hwif->channel, port); |
| 197 |
|
| 198 |
|
| 199 |
/* TBD: could also check ACPI object VALID bits */ |
| 200 |
drive_handle = acpi_get_child(hwif->acpidata->obj_handle, port); |
| 201 |
DEBPRINT("drive %s handle 0x%p\n", drive->name, drive_handle); |
| 202 |
|
| 203 |
return drive_handle; |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* do_drive_get_GTF - get the drive bootup default taskfile settings |
| 208 |
* @drive: the drive for which the taskfile settings should be retrieved |
| 209 |
* @gtf_length: number of bytes of _GTF data returned at @gtf_address |
| 210 |
* @gtf_address: buffer containing _GTF taskfile arrays |
| 211 |
* |
| 212 |
* The _GTF method has no input parameters. |
| 213 |
* It returns a variable number of register set values (registers |
| 214 |
* hex 1F1..1F7, taskfiles). |
| 215 |
* The <variable number> is not known in advance, so have ACPI-CA |
| 216 |
* allocate the buffer as needed and return it, then free it later. |
| 217 |
* |
| 218 |
* The returned @gtf_length and @gtf_address are only valid if the |
| 219 |
* function return value is 0. |
| 220 |
*/ |
| 221 |
int do_drive_get_GTF(ide_drive_t *drive, |
| 222 |
unsigned int *gtf_length, unsigned long *gtf_address, |
| 223 |
unsigned long *obj_loc) |
| 224 |
{ |
| 225 |
acpi_status status; |
| 226 |
struct acpi_buffer output; |
| 227 |
union acpi_object *out_obj; |
| 228 |
ide_hwif_t *hwif = HWIF(drive); |
| 229 |
struct device *dev = hwif->gendev.parent; |
| 230 |
int err = -ENODEV; |
| 231 |
int port; |
| 232 |
|
| 233 |
*gtf_length = 0; |
| 234 |
*gtf_address = 0UL; |
| 235 |
*obj_loc = 0UL; |
| 236 |
|
| 237 |
if (ide_noacpi) |
| 238 |
return 0; |
| 239 |
|
| 240 |
if (!dev) { |
| 241 |
DEBPRINT("no PCI device for %s\n", hwif->name); |
| 242 |
goto out; |
| 243 |
} |
| 244 |
|
| 245 |
if (!hwif->acpidata) { |
| 246 |
DEBPRINT("no ACPI data for %s\n", hwif->name); |
| 247 |
goto out; |
| 248 |
} |
| 249 |
|
| 250 |
port = hwif->channel ? drive->dn - 2: drive->dn; |
| 251 |
|
| 252 |
if (!drive->acpidata) { |
| 253 |
if (port == 0) { |
| 254 |
drive->acpidata = &hwif->acpidata->master; |
| 255 |
hwif->acpidata->master.drive = drive; |
| 256 |
} else { |
| 257 |
drive->acpidata = &hwif->acpidata->slave; |
| 258 |
hwif->acpidata->slave.drive = drive; |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n", |
| 263 |
hwif->name, dev->bus_id, port, hwif->channel); |
| 264 |
|
| 265 |
if (!drive->present) { |
| 266 |
DEBPRINT("%s drive %d:%d not present\n", |
| 267 |
hwif->name, hwif->channel, port); |
| 268 |
goto out; |
| 269 |
} |
| 270 |
|
| 271 |
/* Get this drive's _ADR info. if not already known. */ |
| 272 |
if (!drive->acpidata->obj_handle) { |
| 273 |
drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive); |
| 274 |
if (!drive->acpidata->obj_handle) { |
| 275 |
DEBPRINT("No ACPI object found for %s\n", |
| 276 |
drive->name); |
| 277 |
goto out; |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
/* Setting up output buffer */ |
| 282 |
output.length = ACPI_ALLOCATE_BUFFER; |
| 283 |
output.pointer = NULL; /* ACPI-CA sets this; save/free it later */ |
| 284 |
|
| 285 |
/* _GTF has no input parameters */ |
| 286 |
err = -EIO; |
| 287 |
status = acpi_evaluate_object(drive->acpidata->obj_handle, "_GTF", |
| 288 |
NULL, &output); |
| 289 |
if (ACPI_FAILURE(status)) { |
| 290 |
printk(KERN_DEBUG |
| 291 |
"%s: Run _GTF error: status = 0x%x\n", |
| 292 |
__FUNCTION__, status); |
| 293 |
goto out_free; |
| 294 |
} |
| 295 |
|
| 296 |
if (!output.length || !output.pointer) { |
| 297 |
DEBPRINT("Run _GTF: " |
| 298 |
"length or ptr is NULL (0x%llx, 0x%p)\n", |
| 299 |
(unsigned long long)output.length, |
| 300 |
output.pointer); |
| 301 |
goto out_free; |
| 302 |
} |
| 303 |
|
| 304 |
out_obj = output.pointer; |
| 305 |
if (out_obj->type != ACPI_TYPE_BUFFER) { |
| 306 |
DEBPRINT("Run _GTF: error: " |
| 307 |
"expected object type of ACPI_TYPE_BUFFER, " |
| 308 |
"got 0x%x\n", out_obj->type); |
| 309 |
err = -ENOENT; |
| 310 |
goto out_free; |
| 311 |
} |
| 312 |
|
| 313 |
if (!out_obj->buffer.length || !out_obj->buffer.pointer || |
| 314 |
out_obj->buffer.length % REGS_PER_GTF) { |
| 315 |
printk(KERN_ERR |
| 316 |
"%s: unexpected GTF length (%d) or addr (0x%p)\n", |
| 317 |
__FUNCTION__, out_obj->buffer.length, |
| 318 |
out_obj->buffer.pointer); |
| 319 |
err = -ENOENT; |
| 320 |
goto out_free; |
| 321 |
} |
| 322 |
|
| 323 |
*gtf_length = out_obj->buffer.length; |
| 324 |
*gtf_address = (unsigned long)out_obj->buffer.pointer; |
| 325 |
*obj_loc = (unsigned long)out_obj; |
| 326 |
DEBPRINT("returning gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n", |
| 327 |
*gtf_length, *gtf_address, *obj_loc); |
| 328 |
err = 0; |
| 329 |
out_free: |
| 330 |
acpi_os_free(output.pointer); |
| 331 |
out: |
| 332 |
return err; |
| 333 |
} |
| 334 |
|
| 335 |
/** |
| 336 |
* taskfile_load_raw - send taskfile registers to drive |
| 337 |
* @drive: drive to which output is sent |
| 338 |
* @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7) |
| 339 |
* |
| 340 |
* Outputs IDE taskfile to the drive. |
| 341 |
*/ |
| 342 |
static int taskfile_load_raw(ide_drive_t *drive, |
| 343 |
const struct taskfile_array *gtf) |
| 344 |
{ |
| 345 |
ide_task_t args; |
| 346 |
int err = 0; |
| 347 |
|
| 348 |
DEBPRINT("(0x1f1-1f7): hex: " |
| 349 |
"%02x %02x %02x %02x %02x %02x %02x\n", |
| 350 |
gtf->tfa[0], gtf->tfa[1], gtf->tfa[2], |
| 351 |
gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]); |
| 352 |
|
| 353 |
memset(&args, 0, sizeof(ide_task_t)); |
| 354 |
args.command_type = IDE_DRIVE_TASK_NO_DATA; |
| 355 |
args.data_phase = TASKFILE_IN; |
| 356 |
args.handler = &task_no_data_intr; |
| 357 |
|
| 358 |
/* convert gtf to IDE Taskfile */ |
| 359 |
args.tfRegister[1] = gtf->tfa[0]; /* 0x1f1 */ |
| 360 |
args.tfRegister[2] = gtf->tfa[1]; /* 0x1f2 */ |
| 361 |
args.tfRegister[3] = gtf->tfa[2]; /* 0x1f3 */ |
| 362 |
args.tfRegister[4] = gtf->tfa[3]; /* 0x1f4 */ |
| 363 |
args.tfRegister[5] = gtf->tfa[4]; /* 0x1f5 */ |
| 364 |
args.tfRegister[6] = gtf->tfa[5]; /* 0x1f6 */ |
| 365 |
args.tfRegister[7] = gtf->tfa[6]; /* 0x1f7 */ |
| 366 |
|
| 367 |
if (ide_noacpitfs) |
| 368 |
return err; |
| 369 |
|
| 370 |
err = ide_raw_taskfile(drive, &args, NULL); |
| 371 |
if (err) |
| 372 |
printk(KERN_ERR "%s: ide_raw_taskfile failed: %u\n", |
| 373 |
__FUNCTION__, err); |
| 374 |
|
| 375 |
return err; |
| 376 |
} |
| 377 |
|
| 378 |
/** |
| 379 |
* do_drive_set_taskfiles - write the drive taskfile settings from _GTF |
| 380 |
* @drive: the drive to which the taskfile command should be sent |
| 381 |
* @gtf_length: total number of bytes of _GTF taskfiles |
| 382 |
* @gtf_address: location of _GTF taskfile arrays |
| 383 |
* |
| 384 |
* Write {gtf_address, length gtf_length} in groups of |
| 385 |
* REGS_PER_GTF bytes. |
| 386 |
*/ |
| 387 |
static int do_drive_set_taskfiles(ide_drive_t *drive, |
| 388 |
unsigned int gtf_length, |
| 389 |
unsigned long gtf_address) |
| 390 |
{ |
| 391 |
int err = -ENODEV; |
| 392 |
int gtf_count = gtf_length / REGS_PER_GTF; |
| 393 |
int ix; |
| 394 |
struct taskfile_array *gtf; |
| 395 |
|
| 396 |
if (ide_noacpi) |
| 397 |
return 0; |
| 398 |
|
| 399 |
DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn); |
| 400 |
|
| 401 |
if (!drive->present) |
| 402 |
goto out; |
| 403 |
if (!gtf_count) /* shouldn't be here */ |
| 404 |
goto out; |
| 405 |
|
| 406 |
DEBPRINT("total GTF bytes=%u (0x%x), gtf_count=%d, addr=0x%lx\n", |
| 407 |
gtf_length, gtf_length, gtf_count, gtf_address); |
| 408 |
|
| 409 |
if (gtf_length % REGS_PER_GTF) { |
| 410 |
printk(KERN_ERR "%s: unexpected GTF length (%d)\n", |
| 411 |
__FUNCTION__, gtf_length); |
| 412 |
goto out; |
| 413 |
} |
| 414 |
|
| 415 |
for (ix = 0; ix < gtf_count; ix++) { |
| 416 |
gtf = (struct taskfile_array *) |
| 417 |
(gtf_address + ix * REGS_PER_GTF); |
| 418 |
|
| 419 |
/* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */ |
| 420 |
err = taskfile_load_raw(drive, gtf); |
| 421 |
if (err) |
| 422 |
break; |
| 423 |
} |
| 424 |
|
| 425 |
out: |
| 426 |
return err; |
| 427 |
} |
| 428 |
|
| 429 |
/** |
| 430 |
* ide_acpi_exec_tfs - get then write drive taskfile settings |
| 431 |
* @drive: the drive for which the taskfile settings should be |
| 432 |
* written. |
| 433 |
* |
| 434 |
* According to the ACPI spec this should be called after _STM |
| 435 |
* has been evaluated for the interface. Some ACPI vendors interpret |
| 436 |
* that as a hard requirement and modify the taskfile according |
| 437 |
* to the Identify Drive information passed down with _STM. |
| 438 |
* So one should really make sure to call this only after _STM has |
| 439 |
* been executed. |
| 440 |
*/ |
| 441 |
int ide_acpi_exec_tfs(ide_drive_t *drive) |
| 442 |
{ |
| 443 |
int ret; |
| 444 |
unsigned int gtf_length; |
| 445 |
unsigned long gtf_address; |
| 446 |
unsigned long obj_loc; |
| 447 |
|
| 448 |
if (ide_noacpi) |
| 449 |
return 0; |
| 450 |
|
| 451 |
DEBPRINT("call get_GTF, drive=%s port=%d\n", drive->name, drive->dn); |
| 452 |
|
| 453 |
ret = do_drive_get_GTF(drive, >f_length, >f_address, &obj_loc); |
| 454 |
if (ret < 0) { |
| 455 |
DEBPRINT("get_GTF error (%d)\n", ret); |
| 456 |
return ret; |
| 457 |
} |
| 458 |
|
| 459 |
DEBPRINT("call set_taskfiles, drive=%s\n", drive->name); |
| 460 |
|
| 461 |
ret = do_drive_set_taskfiles(drive, gtf_length, gtf_address); |
| 462 |
acpi_os_free((void *)obj_loc); |
| 463 |
if (ret < 0) { |
| 464 |
DEBPRINT("set_taskfiles error (%d)\n", ret); |
| 465 |
} |
| 466 |
|
| 467 |
DEBPRINT("ret=%d\n", ret); |
| 468 |
|
| 469 |
return ret; |
| 470 |
} |
| 471 |
EXPORT_SYMBOL_GPL(ide_acpi_exec_tfs); |
| 472 |
|
| 473 |
/** |
| 474 |
* ide_acpi_get_timing - get the channel (controller) timings |
| 475 |
* @hwif: target IDE interface (channel) |
| 476 |
* |
| 477 |
* This function executes the _GTM ACPI method for the target channel. |
| 478 |
* |
| 479 |
*/ |
| 480 |
void ide_acpi_get_timing(ide_hwif_t *hwif) |
| 481 |
{ |
| 482 |
acpi_status status; |
| 483 |
struct acpi_buffer output; |
| 484 |
union acpi_object *out_obj; |
| 485 |
|
| 486 |
if (ide_noacpi) |
| 487 |
return; |
| 488 |
|
| 489 |
DEBPRINT("ENTER:\n"); |
| 490 |
|
| 491 |
if (!hwif->acpidata) { |
| 492 |
DEBPRINT("no ACPI data for %s\n", hwif->name); |
| 493 |
return; |
| 494 |
} |
| 495 |
|
| 496 |
/* Setting up output buffer for _GTM */ |
| 497 |
output.length = ACPI_ALLOCATE_BUFFER; |
| 498 |
output.pointer = NULL; /* ACPI-CA sets this; save/free it later */ |
| 499 |
|
| 500 |
/* _GTM has no input parameters */ |
| 501 |
status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_GTM", |
| 502 |
NULL, &output); |
| 503 |
|
| 504 |
DEBPRINT("_GTM status: %d, outptr: 0x%p, outlen: 0x%llx\n", |
| 505 |
status, output.pointer, |
| 506 |
(unsigned long long)output.length); |
| 507 |
|
| 508 |
if (ACPI_FAILURE(status)) { |
| 509 |
DEBPRINT("Run _GTM error: status = 0x%x\n", status); |
| 510 |
return; |
| 511 |
} |
| 512 |
|
| 513 |
if (!output.length || !output.pointer) { |
| 514 |
DEBPRINT("Run _GTM: length or ptr is NULL (0x%llx, 0x%p)\n", |
| 515 |
(unsigned long long)output.length, |
| 516 |
output.pointer); |
| 517 |
acpi_os_free(output.pointer); |
| 518 |
return; |
| 519 |
} |
| 520 |
|
| 521 |
out_obj = output.pointer; |
| 522 |
if (out_obj->type != ACPI_TYPE_BUFFER) { |
| 523 |
acpi_os_free(output.pointer); |
| 524 |
DEBPRINT("Run _GTM: error: " |
| 525 |
"expected object type of ACPI_TYPE_BUFFER, " |
| 526 |
"got 0x%x\n", out_obj->type); |
| 527 |
return; |
| 528 |
} |
| 529 |
|
| 530 |
if (!out_obj->buffer.length || !out_obj->buffer.pointer || |
| 531 |
out_obj->buffer.length != sizeof(struct GTM_buffer)) { |
| 532 |
acpi_os_free(output.pointer); |
| 533 |
printk(KERN_ERR |
| 534 |
"%s: unexpected _GTM length (0x%x)[should be 0x%x] or addr (0x%p)\n", |
| 535 |
__FUNCTION__, out_obj->buffer.length, |
| 536 |
sizeof(struct GTM_buffer), out_obj->buffer.pointer); |
| 537 |
return; |
| 538 |
} |
| 539 |
|
| 540 |
memcpy(&hwif->acpidata->gtm, out_obj->buffer.pointer, |
| 541 |
sizeof(struct GTM_buffer)); |
| 542 |
|
| 543 |
DEBPRINT("_GTM info: ptr: 0x%p, len: 0x%x, exp.len: 0x%Zx\n", |
| 544 |
out_obj->buffer.pointer, out_obj->buffer.length, |
| 545 |
sizeof(struct GTM_buffer)); |
| 546 |
|
| 547 |
DEBPRINT("_GTM fields: 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", |
| 548 |
hwif->acpidata->gtm.PIO_speed0, |
| 549 |
hwif->acpidata->gtm.DMA_speed0, |
| 550 |
hwif->acpidata->gtm.PIO_speed1, |
| 551 |
hwif->acpidata->gtm.DMA_speed1, |
| 552 |
hwif->acpidata->gtm.GTM_flags); |
| 553 |
|
| 554 |
acpi_os_free(output.pointer); |
| 555 |
} |
| 556 |
EXPORT_SYMBOL_GPL(ide_acpi_get_timing); |
| 557 |
|
| 558 |
/** |
| 559 |
* ide_acpi_push_timing - set the channel (controller) timings |
| 560 |
* @hwif: target IDE interface (channel) |
| 561 |
* |
| 562 |
* This function executes the _STM ACPI method for the target channel. |
| 563 |
* |
| 564 |
* _STM requires Identify Drive data, which has to passed as an argument. |
| 565 |
* Unfortunately hd_driveid is a mangled version which we can't readily |
| 566 |
* use; hence we'll get the information afresh. |
| 567 |
*/ |
| 568 |
void ide_acpi_push_timing(ide_hwif_t *hwif) |
| 569 |
{ |
| 570 |
int err; |
| 571 |
acpi_status status; |
| 572 |
struct acpi_object_list input; |
| 573 |
union acpi_object in_params[3]; |
| 574 |
struct ide_acpi_drive_link *master = &hwif->acpidata->master; |
| 575 |
struct ide_acpi_drive_link *slave = &hwif->acpidata->slave; |
| 576 |
|
| 577 |
if (ide_noacpi) |
| 578 |
return; |
| 579 |
|
| 580 |
DEBPRINT("ENTER:\n"); |
| 581 |
|
| 582 |
if (!hwif->acpidata) { |
| 583 |
DEBPRINT("no ACPI data for %s\n", hwif->name); |
| 584 |
return; |
| 585 |
} |
| 586 |
|
| 587 |
if (!master->drive) |
| 588 |
master->drive = &hwif->drives[0]; |
| 589 |
|
| 590 |
if (!slave->drive) |
| 591 |
slave->drive = &hwif->drives[1]; |
| 592 |
|
| 593 |
if (master->drive->present) { |
| 594 |
err = taskfile_lib_get_identify(master->drive, master->idbuff); |
| 595 |
if (err) { |
| 596 |
DEBPRINT("identify device %s failed (%d)\n", |
| 597 |
master->drive->name, err); |
| 598 |
return; |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
if (slave->drive->present) { |
| 603 |
err = taskfile_lib_get_identify(slave->drive, slave->idbuff); |
| 604 |
if (err) { |
| 605 |
DEBPRINT("identify device %s failed (%d)\n", |
| 606 |
slave->drive->name, err); |
| 607 |
return; |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
/* Give the GTM buffer + drive Identify data to the channel via the |
| 612 |
* _STM method: */ |
| 613 |
/* setup input parameters buffer for _STM */ |
| 614 |
input.count = 3; |
| 615 |
input.pointer = in_params; |
| 616 |
in_params[0].type = ACPI_TYPE_BUFFER; |
| 617 |
in_params[0].buffer.length = sizeof(struct GTM_buffer); |
| 618 |
in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm; |
| 619 |
in_params[1].type = ACPI_TYPE_BUFFER; |
| 620 |
in_params[1].buffer.length = sizeof(struct hd_driveid); |
| 621 |
in_params[1].buffer.pointer = (u8 *)&master->idbuff; |
| 622 |
in_params[2].type = ACPI_TYPE_BUFFER; |
| 623 |
in_params[2].buffer.length = sizeof(struct hd_driveid); |
| 624 |
in_params[2].buffer.pointer = (u8 *)&slave->idbuff; |
| 625 |
/* Output buffer: _STM has no output */ |
| 626 |
|
| 627 |
status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_STM", |
| 628 |
&input, NULL); |
| 629 |
|
| 630 |
if (ACPI_FAILURE(status)) { |
| 631 |
DEBPRINT("Run _STM error: status = 0x%x\n", status); |
| 632 |
} |
| 633 |
DEBPRINT("_STM status: %d\n", status); |
| 634 |
} |
| 635 |
EXPORT_SYMBOL_GPL(ide_acpi_push_timing); |
| 636 |
|
| 637 |
void ide_acpi_init(ide_hwif_t *hwif) |
| 638 |
{ |
| 639 |
int unit; |
| 640 |
|
| 641 |
hwif->acpidata = kzalloc(sizeof(struct ide_acpi_hwif_link), GFP_KERNEL); |
| 642 |
if (!hwif->acpidata) |
| 643 |
return; |
| 644 |
|
| 645 |
hwif->acpidata->obj_handle = ide_acpi_hwif_get_handle(hwif); |
| 646 |
if (!hwif->acpidata->obj_handle) { |
| 647 |
DEBPRINT("no ACPI object for %s found\n", hwif->name); |
| 648 |
kfree(hwif->acpidata); |
| 649 |
hwif->acpidata = NULL; |
| 650 |
return; |
| 651 |
} |
| 652 |
|
| 653 |
if (hwif->drives[0].present) { |
| 654 |
hwif->acpidata->master.drive = &hwif->drives[0]; |
| 655 |
hwif->drives[0].acpidata = &hwif->acpidata->master; |
| 656 |
} |
| 657 |
|
| 658 |
if (hwif->drives[1].present) { |
| 659 |
hwif->acpidata->slave.drive = &hwif->drives[1]; |
| 660 |
hwif->drives[1].acpidata = &hwif->acpidata->slave; |
| 661 |
} |
| 662 |
|
| 663 |
/* |
| 664 |
* ACPI requires us to call _STM on startup |
| 665 |
*/ |
| 666 |
ide_acpi_get_timing(hwif); |
| 667 |
ide_acpi_push_timing(hwif); |
| 668 |
|
| 669 |
for (unit = 0; unit < MAX_DRIVES; ++unit) { |
| 670 |
ide_drive_t *drive = &hwif->drives[unit]; |
| 671 |
|
| 672 |
if (drive->present) { |
| 673 |
|
| 674 |
/* Execute ACPI startup code */ |
| 675 |
ide_acpi_exec_tfs(drive); |
| 676 |
} |
| 677 |
|
| 678 |
} |
| 679 |
} |
| 680 |
EXPORT_SYMBOL_GPL(ide_acpi_init); |