ide-acpi.c 18 KB

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