ide-acpi.c 18 KB

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