ide-acpi.c 19 KB

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