ide-acpi.c 18 KB

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