i8237.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * 8237A DMA controller suspend functions.
  4. *
  5. * Written by Pierre Ossman, 2005.
  6. */
  7. #include <linux/dmi.h>
  8. #include <linux/init.h>
  9. #include <linux/syscore_ops.h>
  10. #include <asm/dma.h>
  11. #include <asm/x86_init.h>
  12. /*
  13. * This module just handles suspend/resume issues with the
  14. * 8237A DMA controller (used for ISA and LPC).
  15. * Allocation is handled in kernel/dma.c and normal usage is
  16. * in asm/dma.h.
  17. */
  18. static void i8237A_resume(void)
  19. {
  20. unsigned long flags;
  21. int i;
  22. flags = claim_dma_lock();
  23. dma_outb(0, DMA1_RESET_REG);
  24. dma_outb(0, DMA2_RESET_REG);
  25. for (i = 0; i < 8; i++) {
  26. set_dma_addr(i, 0x000000);
  27. /* DMA count is a bit weird so this is not 0 */
  28. set_dma_count(i, 1);
  29. }
  30. /* Enable cascade DMA or channel 0-3 won't work */
  31. enable_dma(4);
  32. release_dma_lock(flags);
  33. }
  34. static struct syscore_ops i8237_syscore_ops = {
  35. .resume = i8237A_resume,
  36. };
  37. static int __init i8237A_init_ops(void)
  38. {
  39. /*
  40. * From SKL PCH onwards, the legacy DMA device is removed in which the
  41. * I/O ports (81h-83h, 87h, 89h-8Bh, 8Fh) related to it are removed
  42. * as well. All removed ports must return 0xff for a inb() request.
  43. *
  44. * Note: DMA_PAGE_2 (port 0x81) should not be checked for detecting
  45. * the presence of DMA device since it may be used by BIOS to decode
  46. * LPC traffic for POST codes. Original LPC only decodes one byte of
  47. * port 0x80 but some BIOS may choose to enhance PCH LPC port 0x8x
  48. * decoding.
  49. */
  50. if (dma_inb(DMA_PAGE_0) == 0xFF)
  51. return -ENODEV;
  52. /*
  53. * It is not required to load this driver as newer SoC may not
  54. * support 8237 DMA or bus mastering from LPC. Platform firmware
  55. * must announce the support for such legacy devices via
  56. * ACPI_FADT_LEGACY_DEVICES field in FADT table.
  57. */
  58. if (x86_pnpbios_disabled() && dmi_get_bios_year() >= 2017)
  59. return -ENODEV;
  60. register_syscore_ops(&i8237_syscore_ops);
  61. return 0;
  62. }
  63. device_initcall(i8237A_init_ops);