Scoobi_FreeBSD

FreeBSD-10+ patch to enable ACPI CMOS regions

Jul 16th, 2014
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.95 KB | None | 0 0
  1. Index: sys/x86/isa/atrtc.c
  2. ===================================================================
  3. --- sys/x86/isa/atrtc.c (revision 267519)
  4. +++ sys/x86/isa/atrtc.c (working copy)
  5. @@ -31,6 +31,7 @@
  6.  __FBSDID("$FreeBSD$");
  7.  
  8.  #include "opt_isa.h"
  9. +#include "opt_acpi.h"
  10.  
  11.  #include <sys/param.h>
  12.  #include <sys/systm.h>
  13. @@ -53,6 +54,10 @@
  14.  #include <machine/intr_machdep.h>
  15.  #include "clock_if.h"
  16.  
  17. +#include <contrib/dev/acpica/include/acpi.h>
  18. +#include <contrib/dev/acpica/include/accommon.h>
  19. +#include <dev/acpica/acpivar.h>
  20. +
  21.  #define    RTC_LOCK    do { if (!kdb_active) mtx_lock_spin(&clock_lock); } while (0)
  22.  #define    RTC_UNLOCK  do { if (!kdb_active) mtx_unlock_spin(&clock_lock); } while (0)
  23.  
  24. @@ -161,8 +166,33 @@
  25.     struct resource *intr_res;
  26.     void *intr_handler;
  27.     struct eventtimer et;
  28. +   ACPI_HANDLE acpi_handle;    /* Handle of the PNP0B00 node */
  29.  };
  30.  
  31. +static ACPI_STATUS
  32. +acpi_rtc_cmos_handler(UINT32 function, ACPI_PHYSICAL_ADDRESS address, UINT32 width,
  33. +               UINT64 *value, void *context, void *region_context)
  34. +{
  35. +   struct atrtc_softc *sc;
  36. +
  37. +   sc = (struct atrtc_softc *)context;
  38. +   if (!value || !sc)
  39. +       return AE_BAD_PARAMETER;
  40. +   if (width != 8 || address >= 64U)
  41. +       return AE_BAD_PARAMETER;
  42. +   switch (function) {
  43. +       case ACPI_READ:
  44. +           *((UINT8 *)value) = rtcin((int)address);
  45. +           break;
  46. +       case ACPI_WRITE:
  47. +           writertc((int)address, *((UINT8 *)value));
  48. +           break;
  49. +       default:
  50. +           return AE_BAD_PARAMETER;
  51. +   }
  52. +   return AE_OK;
  53. +}
  54. +
  55.  static int
  56.  rtc_start(struct eventtimer *et, sbintime_t first, sbintime_t period)
  57.  {
  58. @@ -245,10 +275,17 @@
  59.     int i;
  60.  
  61.     sc = device_get_softc(dev);
  62. +   sc->acpi_handle = acpi_get_handle(dev);
  63.     sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
  64.         IO_RTC, IO_RTC + 1, 2, RF_ACTIVE);
  65.     if (sc->port_res == NULL)
  66.         device_printf(dev, "Warning: Couldn't map I/O.\n");
  67. +   if (ACPI_FAILURE(AcpiInstallAddressSpaceHandler(sc->acpi_handle,
  68. +                       ACPI_ADR_SPACE_CMOS, acpi_rtc_cmos_handler, NULL, sc)))
  69. +   {
  70. +       device_printf(dev, "Error registering ACPI CMOS address space handler.\n");
  71. +       return 0;
  72. +   }
  73.     atrtc_start();
  74.     clock_register(dev, 1000000);
  75.     bzero(&sc->et, sizeof(struct eventtimer));
  76. @@ -286,6 +323,15 @@
  77.     return(0);
  78.  }
  79.  
  80. +static int atrtc_detach(device_t dev)
  81. +{
  82. +   struct atrtc_softc *sc;
  83. +
  84. +   sc = device_get_softc(dev);
  85. +   AcpiRemoveAddressSpaceHandler(sc->acpi_handle, ACPI_ADR_SPACE_CMOS, acpi_rtc_cmos_handler);
  86. +   return bus_generic_detach(dev);
  87. +}
  88. +
  89.  static int
  90.  atrtc_resume(device_t dev)
  91.  {
  92. @@ -366,7 +412,7 @@
  93.     /* Device interface */
  94.     DEVMETHOD(device_probe,     atrtc_probe),
  95.     DEVMETHOD(device_attach,    atrtc_attach),
  96. -   DEVMETHOD(device_detach,    bus_generic_detach),
  97. +   DEVMETHOD(device_detach,    atrtc_detach),
  98.     DEVMETHOD(device_shutdown,  bus_generic_shutdown),
  99.     DEVMETHOD(device_suspend,   bus_generic_suspend),
  100.         /* XXX stop statclock? */
  101. @@ -402,3 +448,4 @@
  102.         rtcin(RTC_STATUSA), rtcin(RTC_STATUSB), rtcin(RTC_INTR));
  103.  }
  104.  #endif /* DDB */
  105. +
Add Comment
Please, Sign In to add comment