ide-acpi.c 19 KB

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