ide-acpi.c 19 KB

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