csrt.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Support for Core System Resources Table (CSRT)
  3. *
  4. * Copyright (C) 2013, Intel Corporation
  5. * Authors: Mika Westerberg <mika.westerberg@linux.intel.com>
  6. * Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #define pr_fmt(fmt) "ACPI: CSRT: " fmt
  13. #include <linux/acpi.h>
  14. #include <linux/device.h>
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/sizes.h>
  19. ACPI_MODULE_NAME("CSRT");
  20. static int __init acpi_csrt_parse_shared_info(struct platform_device *pdev,
  21. const struct acpi_csrt_group *grp)
  22. {
  23. const struct acpi_csrt_shared_info *si;
  24. struct resource res[3];
  25. size_t nres;
  26. int ret;
  27. memset(res, 0, sizeof(res));
  28. nres = 0;
  29. si = (const struct acpi_csrt_shared_info *)&grp[1];
  30. /*
  31. * The peripherals that are listed on CSRT typically support only
  32. * 32-bit addresses so we only use the low part of MMIO base for
  33. * now.
  34. */
  35. if (!si->mmio_base_high && si->mmio_base_low) {
  36. /*
  37. * There is no size of the memory resource in shared_info
  38. * so we assume that it is 4k here.
  39. */
  40. res[nres].start = si->mmio_base_low;
  41. res[nres].end = res[0].start + SZ_4K - 1;
  42. res[nres++].flags = IORESOURCE_MEM;
  43. }
  44. if (si->gsi_interrupt) {
  45. int irq = acpi_register_gsi(NULL, si->gsi_interrupt,
  46. si->interrupt_mode,
  47. si->interrupt_polarity);
  48. res[nres].start = irq;
  49. res[nres].end = irq;
  50. res[nres++].flags = IORESOURCE_IRQ;
  51. }
  52. if (si->base_request_line || si->num_handshake_signals) {
  53. /*
  54. * We pass the driver a DMA resource describing the range
  55. * of request lines the device supports.
  56. */
  57. res[nres].start = si->base_request_line;
  58. res[nres].end = res[nres].start + si->num_handshake_signals - 1;
  59. res[nres++].flags = IORESOURCE_DMA;
  60. }
  61. ret = platform_device_add_resources(pdev, res, nres);
  62. if (ret) {
  63. if (si->gsi_interrupt)
  64. acpi_unregister_gsi(si->gsi_interrupt);
  65. return ret;
  66. }
  67. return 0;
  68. }
  69. static int __init
  70. acpi_csrt_parse_resource_group(const struct acpi_csrt_group *grp)
  71. {
  72. struct platform_device *pdev;
  73. char vendor[5], name[16];
  74. int ret, i;
  75. vendor[0] = grp->vendor_id;
  76. vendor[1] = grp->vendor_id >> 8;
  77. vendor[2] = grp->vendor_id >> 16;
  78. vendor[3] = grp->vendor_id >> 24;
  79. vendor[4] = '\0';
  80. if (grp->shared_info_length != sizeof(struct acpi_csrt_shared_info))
  81. return -ENODEV;
  82. snprintf(name, sizeof(name), "%s%04X", vendor, grp->device_id);
  83. pdev = platform_device_alloc(name, PLATFORM_DEVID_AUTO);
  84. if (!pdev)
  85. return -ENOMEM;
  86. /* Add resources based on the shared info */
  87. ret = acpi_csrt_parse_shared_info(pdev, grp);
  88. if (ret)
  89. goto fail;
  90. ret = platform_device_add(pdev);
  91. if (ret)
  92. goto fail;
  93. for (i = 0; i < pdev->num_resources; i++)
  94. dev_dbg(&pdev->dev, "%pR\n", &pdev->resource[i]);
  95. return 0;
  96. fail:
  97. platform_device_put(pdev);
  98. return ret;
  99. }
  100. /*
  101. * CSRT or Core System Resources Table is a proprietary ACPI table
  102. * introduced by Microsoft. This table can contain devices that are not in
  103. * the system DSDT table. In particular DMA controllers might be described
  104. * here.
  105. *
  106. * We present these devices as normal platform devices that don't have ACPI
  107. * IDs or handle. The platform device name will be something like
  108. * <VENDOR><DEVID>.<n>.auto for example: INTL9C06.0.auto.
  109. */
  110. void __init acpi_csrt_init(void)
  111. {
  112. struct acpi_csrt_group *grp, *end;
  113. struct acpi_table_csrt *csrt;
  114. acpi_status status;
  115. int ret;
  116. status = acpi_get_table(ACPI_SIG_CSRT, 0,
  117. (struct acpi_table_header **)&csrt);
  118. if (ACPI_FAILURE(status)) {
  119. if (status != AE_NOT_FOUND)
  120. pr_warn("failed to get the CSRT table\n");
  121. return;
  122. }
  123. pr_debug("parsing CSRT table for devices\n");
  124. grp = (struct acpi_csrt_group *)(csrt + 1);
  125. end = (struct acpi_csrt_group *)((void *)csrt + csrt->header.length);
  126. while (grp < end) {
  127. ret = acpi_csrt_parse_resource_group(grp);
  128. if (ret) {
  129. pr_warn("error in parsing resource group: %d\n", ret);
  130. return;
  131. }
  132. grp = (struct acpi_csrt_group *)((void *)grp + grp->length);
  133. }
  134. }