ide-acpi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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, __FUNCTION__, ## args)
  52. #else
  53. #define DEBPRINT(fmt, args...) do {} while (0)
  54. #endif /* DEBUGGING */
  55. extern int ide_noacpi;
  56. extern int ide_noacpitfs;
  57. extern int ide_noacpionboot;
  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. * ide_acpi_drive_get_handle - Get ACPI object handle for a given drive
  179. * @drive: device to locate
  180. *
  181. * Retrieves the object handle of a given drive. According to the ACPI
  182. * spec the drive is a child of the hwif.
  183. *
  184. * Returns handle on success, 0 on error.
  185. */
  186. static acpi_handle ide_acpi_drive_get_handle(ide_drive_t *drive)
  187. {
  188. ide_hwif_t *hwif = HWIF(drive);
  189. int port;
  190. acpi_handle drive_handle;
  191. if (!hwif->acpidata)
  192. return NULL;
  193. if (!hwif->acpidata->obj_handle)
  194. return NULL;
  195. port = hwif->channel ? drive->dn - 2: drive->dn;
  196. DEBPRINT("ENTER: %s at channel#: %d port#: %d\n",
  197. drive->name, hwif->channel, port);
  198. /* TBD: could also check ACPI object VALID bits */
  199. drive_handle = acpi_get_child(hwif->acpidata->obj_handle, port);
  200. DEBPRINT("drive %s handle 0x%p\n", drive->name, drive_handle);
  201. return drive_handle;
  202. }
  203. /**
  204. * do_drive_get_GTF - get the drive bootup default taskfile settings
  205. * @drive: the drive for which the taskfile settings should be retrieved
  206. * @gtf_length: number of bytes of _GTF data returned at @gtf_address
  207. * @gtf_address: buffer containing _GTF taskfile arrays
  208. *
  209. * The _GTF method has no input parameters.
  210. * It returns a variable number of register set values (registers
  211. * hex 1F1..1F7, taskfiles).
  212. * The <variable number> is not known in advance, so have ACPI-CA
  213. * allocate the buffer as needed and return it, then free it later.
  214. *
  215. * The returned @gtf_length and @gtf_address are only valid if the
  216. * function return value is 0.
  217. */
  218. static int do_drive_get_GTF(ide_drive_t *drive,
  219. unsigned int *gtf_length, unsigned long *gtf_address,
  220. unsigned long *obj_loc)
  221. {
  222. acpi_status status;
  223. struct acpi_buffer output;
  224. union acpi_object *out_obj;
  225. ide_hwif_t *hwif = HWIF(drive);
  226. struct device *dev = hwif->gendev.parent;
  227. int err = -ENODEV;
  228. int port;
  229. *gtf_length = 0;
  230. *gtf_address = 0UL;
  231. *obj_loc = 0UL;
  232. if (ide_noacpi)
  233. return 0;
  234. if (!dev) {
  235. DEBPRINT("no PCI device for %s\n", hwif->name);
  236. goto out;
  237. }
  238. if (!hwif->acpidata) {
  239. DEBPRINT("no ACPI data for %s\n", hwif->name);
  240. goto out;
  241. }
  242. port = hwif->channel ? drive->dn - 2: drive->dn;
  243. DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
  244. hwif->name, dev->bus_id, port, hwif->channel);
  245. if (!drive->present) {
  246. DEBPRINT("%s drive %d:%d not present\n",
  247. hwif->name, hwif->channel, port);
  248. goto out;
  249. }
  250. /* Get this drive's _ADR info. if not already known. */
  251. if (!drive->acpidata->obj_handle) {
  252. drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
  253. if (!drive->acpidata->obj_handle) {
  254. DEBPRINT("No ACPI object found for %s\n",
  255. drive->name);
  256. goto out;
  257. }
  258. }
  259. /* Setting up output buffer */
  260. output.length = ACPI_ALLOCATE_BUFFER;
  261. output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
  262. /* _GTF has no input parameters */
  263. err = -EIO;
  264. status = acpi_evaluate_object(drive->acpidata->obj_handle, "_GTF",
  265. NULL, &output);
  266. if (ACPI_FAILURE(status)) {
  267. printk(KERN_DEBUG
  268. "%s: Run _GTF error: status = 0x%x\n",
  269. __FUNCTION__, status);
  270. goto out;
  271. }
  272. if (!output.length || !output.pointer) {
  273. DEBPRINT("Run _GTF: "
  274. "length or ptr is NULL (0x%llx, 0x%p)\n",
  275. (unsigned long long)output.length,
  276. output.pointer);
  277. goto out;
  278. }
  279. out_obj = output.pointer;
  280. if (out_obj->type != ACPI_TYPE_BUFFER) {
  281. DEBPRINT("Run _GTF: error: "
  282. "expected object type of ACPI_TYPE_BUFFER, "
  283. "got 0x%x\n", out_obj->type);
  284. err = -ENOENT;
  285. kfree(output.pointer);
  286. goto out;
  287. }
  288. if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
  289. out_obj->buffer.length % REGS_PER_GTF) {
  290. printk(KERN_ERR
  291. "%s: unexpected GTF length (%d) or addr (0x%p)\n",
  292. __FUNCTION__, out_obj->buffer.length,
  293. out_obj->buffer.pointer);
  294. err = -ENOENT;
  295. kfree(output.pointer);
  296. goto out;
  297. }
  298. *gtf_length = out_obj->buffer.length;
  299. *gtf_address = (unsigned long)out_obj->buffer.pointer;
  300. *obj_loc = (unsigned long)out_obj;
  301. DEBPRINT("returning gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
  302. *gtf_length, *gtf_address, *obj_loc);
  303. err = 0;
  304. out:
  305. return err;
  306. }
  307. /**
  308. * taskfile_load_raw - send taskfile registers to drive
  309. * @drive: drive to which output is sent
  310. * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
  311. *
  312. * Outputs IDE taskfile to the drive.
  313. */
  314. static int taskfile_load_raw(ide_drive_t *drive,
  315. const struct taskfile_array *gtf)
  316. {
  317. ide_task_t args;
  318. int err = 0;
  319. DEBPRINT("(0x1f1-1f7): hex: "
  320. "%02x %02x %02x %02x %02x %02x %02x\n",
  321. gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
  322. gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
  323. memset(&args, 0, sizeof(ide_task_t));
  324. /* convert gtf to IDE Taskfile */
  325. memcpy(&args.tf_array[7], &gtf->tfa, 7);
  326. args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
  327. if (ide_noacpitfs) {
  328. DEBPRINT("_GTF execution disabled\n");
  329. return err;
  330. }
  331. err = ide_no_data_taskfile(drive, &args);
  332. if (err)
  333. printk(KERN_ERR "%s: ide_no_data_taskfile failed: %u\n",
  334. __FUNCTION__, err);
  335. return err;
  336. }
  337. /**
  338. * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
  339. * @drive: the drive to which the taskfile command should be sent
  340. * @gtf_length: total number of bytes of _GTF taskfiles
  341. * @gtf_address: location of _GTF taskfile arrays
  342. *
  343. * Write {gtf_address, length gtf_length} in groups of
  344. * REGS_PER_GTF bytes.
  345. */
  346. static int do_drive_set_taskfiles(ide_drive_t *drive,
  347. unsigned int gtf_length,
  348. unsigned long gtf_address)
  349. {
  350. int rc = -ENODEV, err;
  351. int gtf_count = gtf_length / REGS_PER_GTF;
  352. int ix;
  353. struct taskfile_array *gtf;
  354. if (ide_noacpi)
  355. return 0;
  356. DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn);
  357. if (!drive->present)
  358. goto out;
  359. if (!gtf_count) /* shouldn't be here */
  360. goto out;
  361. DEBPRINT("total GTF bytes=%u (0x%x), gtf_count=%d, addr=0x%lx\n",
  362. gtf_length, gtf_length, gtf_count, gtf_address);
  363. if (gtf_length % REGS_PER_GTF) {
  364. printk(KERN_ERR "%s: unexpected GTF length (%d)\n",
  365. __FUNCTION__, gtf_length);
  366. goto out;
  367. }
  368. rc = 0;
  369. for (ix = 0; ix < gtf_count; ix++) {
  370. gtf = (struct taskfile_array *)
  371. (gtf_address + ix * REGS_PER_GTF);
  372. /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
  373. err = taskfile_load_raw(drive, gtf);
  374. if (err)
  375. rc = err;
  376. }
  377. out:
  378. return rc;
  379. }
  380. /**
  381. * ide_acpi_exec_tfs - get then write drive taskfile settings
  382. * @drive: the drive for which the taskfile settings should be
  383. * written.
  384. *
  385. * According to the ACPI spec this should be called after _STM
  386. * has been evaluated for the interface. Some ACPI vendors interpret
  387. * that as a hard requirement and modify the taskfile according
  388. * to the Identify Drive information passed down with _STM.
  389. * So one should really make sure to call this only after _STM has
  390. * been executed.
  391. */
  392. int ide_acpi_exec_tfs(ide_drive_t *drive)
  393. {
  394. int ret;
  395. unsigned int gtf_length;
  396. unsigned long gtf_address;
  397. unsigned long obj_loc;
  398. if (ide_noacpi)
  399. return 0;
  400. DEBPRINT("call get_GTF, drive=%s port=%d\n", drive->name, drive->dn);
  401. ret = do_drive_get_GTF(drive, &gtf_length, &gtf_address, &obj_loc);
  402. if (ret < 0) {
  403. DEBPRINT("get_GTF error (%d)\n", ret);
  404. return ret;
  405. }
  406. DEBPRINT("call set_taskfiles, drive=%s\n", drive->name);
  407. ret = do_drive_set_taskfiles(drive, gtf_length, gtf_address);
  408. kfree((void *)obj_loc);
  409. if (ret < 0) {
  410. DEBPRINT("set_taskfiles error (%d)\n", ret);
  411. }
  412. DEBPRINT("ret=%d\n", ret);
  413. return ret;
  414. }
  415. /**
  416. * ide_acpi_get_timing - get the channel (controller) timings
  417. * @hwif: target IDE interface (channel)
  418. *
  419. * This function executes the _GTM ACPI method for the target channel.
  420. *
  421. */
  422. void ide_acpi_get_timing(ide_hwif_t *hwif)
  423. {
  424. acpi_status status;
  425. struct acpi_buffer output;
  426. union acpi_object *out_obj;
  427. if (ide_noacpi)
  428. return;
  429. DEBPRINT("ENTER:\n");
  430. if (!hwif->acpidata) {
  431. DEBPRINT("no ACPI data for %s\n", hwif->name);
  432. return;
  433. }
  434. /* Setting up output buffer for _GTM */
  435. output.length = ACPI_ALLOCATE_BUFFER;
  436. output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
  437. /* _GTM has no input parameters */
  438. status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_GTM",
  439. NULL, &output);
  440. DEBPRINT("_GTM status: %d, outptr: 0x%p, outlen: 0x%llx\n",
  441. status, output.pointer,
  442. (unsigned long long)output.length);
  443. if (ACPI_FAILURE(status)) {
  444. DEBPRINT("Run _GTM error: status = 0x%x\n", status);
  445. return;
  446. }
  447. if (!output.length || !output.pointer) {
  448. DEBPRINT("Run _GTM: length or ptr is NULL (0x%llx, 0x%p)\n",
  449. (unsigned long long)output.length,
  450. output.pointer);
  451. kfree(output.pointer);
  452. return;
  453. }
  454. out_obj = output.pointer;
  455. if (out_obj->type != ACPI_TYPE_BUFFER) {
  456. kfree(output.pointer);
  457. DEBPRINT("Run _GTM: error: "
  458. "expected object type of ACPI_TYPE_BUFFER, "
  459. "got 0x%x\n", out_obj->type);
  460. return;
  461. }
  462. if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
  463. out_obj->buffer.length != sizeof(struct GTM_buffer)) {
  464. kfree(output.pointer);
  465. printk(KERN_ERR
  466. "%s: unexpected _GTM length (0x%x)[should be 0x%zx] or "
  467. "addr (0x%p)\n",
  468. __FUNCTION__, out_obj->buffer.length,
  469. sizeof(struct GTM_buffer), out_obj->buffer.pointer);
  470. return;
  471. }
  472. memcpy(&hwif->acpidata->gtm, out_obj->buffer.pointer,
  473. sizeof(struct GTM_buffer));
  474. DEBPRINT("_GTM info: ptr: 0x%p, len: 0x%x, exp.len: 0x%Zx\n",
  475. out_obj->buffer.pointer, out_obj->buffer.length,
  476. sizeof(struct GTM_buffer));
  477. DEBPRINT("_GTM fields: 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
  478. hwif->acpidata->gtm.PIO_speed0,
  479. hwif->acpidata->gtm.DMA_speed0,
  480. hwif->acpidata->gtm.PIO_speed1,
  481. hwif->acpidata->gtm.DMA_speed1,
  482. hwif->acpidata->gtm.GTM_flags);
  483. kfree(output.pointer);
  484. }
  485. /**
  486. * ide_acpi_push_timing - set the channel (controller) timings
  487. * @hwif: target IDE interface (channel)
  488. *
  489. * This function executes the _STM ACPI method for the target channel.
  490. *
  491. * _STM requires Identify Drive data, which has to passed as an argument.
  492. * Unfortunately hd_driveid is a mangled version which we can't readily
  493. * use; hence we'll get the information afresh.
  494. */
  495. void ide_acpi_push_timing(ide_hwif_t *hwif)
  496. {
  497. acpi_status status;
  498. struct acpi_object_list input;
  499. union acpi_object in_params[3];
  500. struct ide_acpi_drive_link *master = &hwif->acpidata->master;
  501. struct ide_acpi_drive_link *slave = &hwif->acpidata->slave;
  502. if (ide_noacpi)
  503. return;
  504. DEBPRINT("ENTER:\n");
  505. if (!hwif->acpidata) {
  506. DEBPRINT("no ACPI data for %s\n", hwif->name);
  507. return;
  508. }
  509. /* Give the GTM buffer + drive Identify data to the channel via the
  510. * _STM method: */
  511. /* setup input parameters buffer for _STM */
  512. input.count = 3;
  513. input.pointer = in_params;
  514. in_params[0].type = ACPI_TYPE_BUFFER;
  515. in_params[0].buffer.length = sizeof(struct GTM_buffer);
  516. in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm;
  517. in_params[1].type = ACPI_TYPE_BUFFER;
  518. in_params[1].buffer.length = sizeof(struct hd_driveid);
  519. in_params[1].buffer.pointer = (u8 *)&master->idbuff;
  520. in_params[2].type = ACPI_TYPE_BUFFER;
  521. in_params[2].buffer.length = sizeof(struct hd_driveid);
  522. in_params[2].buffer.pointer = (u8 *)&slave->idbuff;
  523. /* Output buffer: _STM has no output */
  524. status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_STM",
  525. &input, NULL);
  526. if (ACPI_FAILURE(status)) {
  527. DEBPRINT("Run _STM error: status = 0x%x\n", status);
  528. }
  529. DEBPRINT("_STM status: %d\n", status);
  530. }
  531. /**
  532. * ide_acpi_set_state - set the channel power state
  533. * @hwif: target IDE interface
  534. * @on: state, on/off
  535. *
  536. * This function executes the _PS0/_PS3 ACPI method to set the power state.
  537. * ACPI spec requires _PS0 when IDE power on and _PS3 when power off
  538. */
  539. void ide_acpi_set_state(ide_hwif_t *hwif, int on)
  540. {
  541. int unit;
  542. if (ide_noacpi || ide_noacpi_psx)
  543. return;
  544. DEBPRINT("ENTER:\n");
  545. if (!hwif->acpidata) {
  546. DEBPRINT("no ACPI data for %s\n", hwif->name);
  547. return;
  548. }
  549. /* channel first and then drives for power on and verse versa for power off */
  550. if (on)
  551. acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0);
  552. for (unit = 0; unit < MAX_DRIVES; ++unit) {
  553. ide_drive_t *drive = &hwif->drives[unit];
  554. if (!drive->acpidata->obj_handle)
  555. drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
  556. if (drive->acpidata->obj_handle && drive->present) {
  557. acpi_bus_set_power(drive->acpidata->obj_handle,
  558. on? ACPI_STATE_D0: ACPI_STATE_D3);
  559. }
  560. }
  561. if (!on)
  562. acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D3);
  563. }
  564. /**
  565. * ide_acpi_init - initialize the ACPI link for an IDE interface
  566. * @hwif: target IDE interface (channel)
  567. *
  568. * The ACPI spec is not quite clear when the drive identify buffer
  569. * should be obtained. Calling IDENTIFY DEVICE during shutdown
  570. * is not the best of ideas as the drive might already being put to
  571. * sleep. And obviously we can't call it during resume.
  572. * So we get the information during startup; but this means that
  573. * any changes during run-time will be lost after resume.
  574. */
  575. void ide_acpi_init(ide_hwif_t *hwif)
  576. {
  577. ide_acpi_blacklist();
  578. hwif->acpidata = kzalloc(sizeof(struct ide_acpi_hwif_link), GFP_KERNEL);
  579. if (!hwif->acpidata)
  580. return;
  581. hwif->acpidata->obj_handle = ide_acpi_hwif_get_handle(hwif);
  582. if (!hwif->acpidata->obj_handle) {
  583. DEBPRINT("no ACPI object for %s found\n", hwif->name);
  584. kfree(hwif->acpidata);
  585. hwif->acpidata = NULL;
  586. }
  587. }
  588. void ide_acpi_port_init_devices(ide_hwif_t *hwif)
  589. {
  590. ide_drive_t *drive;
  591. int i, err;
  592. if (hwif->acpidata == NULL)
  593. return;
  594. /*
  595. * The ACPI spec mandates that we send information
  596. * for both drives, regardless whether they are connected
  597. * or not.
  598. */
  599. hwif->drives[0].acpidata = &hwif->acpidata->master;
  600. hwif->drives[1].acpidata = &hwif->acpidata->slave;
  601. /*
  602. * Send IDENTIFY for each drive
  603. */
  604. for (i = 0; i < MAX_DRIVES; i++) {
  605. drive = &hwif->drives[i];
  606. memset(drive->acpidata, 0, sizeof(*drive->acpidata));
  607. if (!drive->present)
  608. continue;
  609. err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff);
  610. if (err)
  611. DEBPRINT("identify device %s failed (%d)\n",
  612. drive->name, err);
  613. }
  614. if (ide_noacpionboot) {
  615. DEBPRINT("ACPI methods disabled on boot\n");
  616. return;
  617. }
  618. /* ACPI _PS0 before _STM */
  619. ide_acpi_set_state(hwif, 1);
  620. /*
  621. * ACPI requires us to call _STM on startup
  622. */
  623. ide_acpi_get_timing(hwif);
  624. ide_acpi_push_timing(hwif);
  625. for (i = 0; i < MAX_DRIVES; i++) {
  626. drive = &hwif->drives[i];
  627. if (drive->present)
  628. /* Execute ACPI startup code */
  629. ide_acpi_exec_tfs(drive);
  630. }
  631. }