Subversion Repositories Kolibri OS

Rev

Rev 1498 | Rev 1625 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. #include <types.h>
  3. #include <syscall.h>
  4.  
  5. #include "acpi.h"
  6.  
  7. #define ACPI_NS_ROOT_PATH       "\\"
  8. #define ACPI_NS_SYSTEM_BUS      "_SB_"
  9.  
  10. enum acpi_irq_model_id {
  11.         ACPI_IRQ_MODEL_PIC = 0,
  12.         ACPI_IRQ_MODEL_IOAPIC,
  13.         ACPI_IRQ_MODEL_IOSAPIC,
  14.         ACPI_IRQ_MODEL_PLATFORM,
  15.         ACPI_IRQ_MODEL_COUNT
  16. };
  17.  
  18.  
  19. #define  addr_offset(addr, off) \
  20.     (addr_t)((addr_t)(addr) + (addr_t)(off))
  21.  
  22. //#define acpi_remap( addr ) \
  23. //    (addr_t)((addr_t)(addr) + OS_BASE)
  24.  
  25. #define acpi_remap( addr ) MapIoMem((void*)(addr),4096, 0x01)
  26.  
  27. ACPI_STATUS
  28. get_device_by_hid_callback(ACPI_HANDLE obj, u32_t depth, void* context,
  29.     void** retval)
  30. {
  31.     static u32_t counter = 0;
  32.     static char buff[256];
  33.  
  34.         ACPI_STATUS status;
  35.  
  36.     ACPI_BUFFER buffer;
  37.  
  38.     ACPI_DEVICE_INFO *info;
  39.  
  40.    // *retval = NULL;
  41.  
  42.     buffer.Length = 255;
  43.     buffer.Pointer = buff;
  44.  
  45.     status = AcpiGetName(obj, ACPI_FULL_PATHNAME, &buffer);
  46.     if (status != AE_OK) {
  47.         return AE_CTRL_TERMINATE;
  48.     }
  49.  
  50.     buff[buffer.Length] = '\0';
  51.  
  52.     dbgprintf("device %d %s ", counter, buff);
  53.  
  54.     status = AcpiGetObjectInfo(obj, &info);
  55.  
  56.     if (ACPI_SUCCESS (status))
  57.     {
  58.         if (info->Valid & ACPI_VALID_HID)
  59.             dbgprintf (" HID: %s", info->HardwareId.String);
  60.  
  61.     };
  62.  
  63.     dbgprintf("\n");
  64.     counter++;
  65.  
  66.         return AE_OK;
  67. }
  68.  
  69. prt_walk_table(ACPI_BUFFER *prt)
  70. {
  71.     ACPI_PCI_ROUTING_TABLE *entry;
  72.     char *prtptr;
  73.  
  74.     /* First check to see if there is a table to walk. */
  75.     if (prt == NULL || prt->Pointer == NULL)
  76.         return;
  77.  
  78.     /* Walk the table executing the handler function for each entry. */
  79.     prtptr = prt->Pointer;
  80.     entry = (ACPI_PCI_ROUTING_TABLE *)prtptr;
  81.     while (entry->Length != 0)
  82.     {
  83.  
  84.         dbgprintf("adress: %x %x  ", (u32_t)(entry->Address>>32),
  85.                   (u32_t)entry->Address);
  86.         dbgprintf("pin: %d  index: %d  source: %s\n",
  87.                    entry->Pin,
  88.                    entry->SourceIndex,
  89.                    entry->Source);
  90.  
  91. //      handler(entry, arg);
  92.         prtptr += entry->Length;
  93.         entry = (ACPI_PCI_ROUTING_TABLE *)prtptr;
  94.     }
  95. }
  96.  
  97.  
  98. u32_t drvEntry(int action, char *cmdline)
  99. {
  100.     u32_t retval;
  101.  
  102.     ACPI_STATUS status;
  103.  
  104.     int i;
  105.  
  106.     if(action != 1)
  107.         return 0;
  108.  
  109.     status = AcpiReallocateRootTable();
  110.     if (ACPI_FAILURE(status)) {
  111.         dbgprintf("Unable to reallocate ACPI tables\n");
  112.         goto err;
  113.     }
  114.  
  115.     status = AcpiInitializeSubsystem();
  116.     if (status != AE_OK) {
  117.           dbgprintf("AcpiInitializeSubsystem failed (%s)\n",
  118.                      AcpiFormatException(status));
  119.           goto err;
  120.     }
  121.  
  122.     status = AcpiInitializeTables(NULL, 0, TRUE);
  123.     if (status != AE_OK) {
  124.           dbgprintf("AcpiInitializeTables failed (%s)\n",
  125.                      AcpiFormatException(status));
  126.           goto err;
  127.     }
  128.  
  129.     status = AcpiLoadTables();
  130.     if (status != AE_OK) {
  131.           dbgprintf("AcpiLoadTables failed (%s)\n",
  132.                      AcpiFormatException(status));
  133.           goto err;
  134.     }
  135.  
  136.     u32_t mode = ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE;
  137.  
  138.     status = AcpiEnableSubsystem(mode);
  139.     if (status != AE_OK) {
  140.         dbgprintf("AcpiEnableSubsystem failed (%s)\n",
  141.             AcpiFormatException(status));
  142.         goto err;
  143.     }
  144.  
  145.     status = AcpiInitializeObjects (ACPI_FULL_INITIALIZATION);
  146.     if (ACPI_FAILURE (status))
  147.     {
  148.         dbgprintf("AcpiInitializeObjects failed (%s)\n",
  149.             AcpiFormatException(status));
  150.         goto err;
  151.     }
  152.  
  153.     AcpiWalkNamespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 4,
  154.                       get_device_by_hid_callback, NULL, NULL, NULL);
  155.  
  156. #if 0
  157.  
  158.     ACPI_OBJECT obj;
  159.     ACPI_HANDLE bus_handle;
  160.     ACPI_HANDLE pci_root;
  161.  
  162.     status = AcpiGetHandle(0, "\\_SB_", &bus_handle);
  163.     dbgprintf("system bus handle %x\n", bus_handle);
  164.  
  165.     status = AcpiGetHandle(bus_handle, "PCI0", &pci_root);
  166.  
  167.     if (status != AE_OK) {
  168.         dbgprintf("AcpiGetHandle failed (%s)\n",
  169.             AcpiFormatException(status));
  170.         goto err;
  171.     }
  172.  
  173.     dbgprintf("pci root handle %x\n\n", pci_root);
  174.  
  175.     ACPI_BUFFER prt_buffer;
  176.  
  177.     prt_buffer.Length = ACPI_ALLOCATE_BUFFER;
  178.     prt_buffer.Pointer = NULL;
  179.  
  180.     status = AcpiGetIrqRoutingTable(pci_root, &prt_buffer);
  181.  
  182.     if (status != AE_OK) {
  183.         dbgprintf("AcpiGetIrqRoutingTable failed (%s)\n",
  184.             AcpiFormatException(status));
  185.         goto err;
  186.     }
  187.  
  188.     prt_walk_table(&prt_buffer);
  189.  
  190.  
  191.     ACPI_OBJECT arg = { ACPI_TYPE_INTEGER };
  192.     ACPI_OBJECT_LIST arg_list = { 1, &arg };
  193.  
  194.     arg.Integer.Value = ACPI_IRQ_MODEL_IOAPIC;
  195.  
  196.     dbgprintf("\nset ioapic mode\n\n");
  197.  
  198.     status = AcpiEvaluateObject(NULL, "\\_PIC", &arg_list, NULL);
  199.  
  200.     if (ACPI_FAILURE(status)) {
  201.         dbgprintf("AcpiEvaluateObject failed (%s)\n",
  202.             AcpiFormatException(status));
  203.  //       goto err;
  204.     }
  205.  
  206.  
  207.     status = AcpiGetIrqRoutingTable(pci_root, &prt_buffer);
  208.  
  209.     if (status != AE_OK) {
  210.         dbgprintf("AcpiGetIrqRoutingTable failed (%s)\n",
  211.             AcpiFormatException(status));
  212.         goto err;
  213.     }
  214.  
  215.     prt_walk_table(&prt_buffer);
  216.  
  217.     u8_t pin = PciRead8 (0, (31<<3) | 1, 0x3D);
  218.     dbgprintf("bus 0 device 31 function 1 pin %d\n", pin-1);
  219.  
  220.     pin = PciRead8 (0, (31<<3) | 2, 0x3D);
  221.     dbgprintf("bus 0 device 31 function 2 pin %d\n", pin-1);
  222.  
  223.     pin = PciRead8 (0, (31<<3) | 3, 0x3D);
  224.     dbgprintf("bus 0 device 31 function 3 pin %d\n", pin-1);
  225.  
  226.     pin = PciRead8 (0, (31<<3) | 4, 0x3D);
  227.     dbgprintf("bus 0 device 31 function 4 pin %d\n", pin-1);
  228.  
  229.     pin = PciRead8 (0, (31<<3) | 5, 0x3D);
  230.     dbgprintf("bus 0 device 31 function 5 pin %d\n", pin-1);
  231.  
  232.     pin = PciRead8 (0, (31<<3) | 6, 0x3D);
  233.     dbgprintf("bus 0 device 31 function 6 pin %d\n", pin-1);
  234.  
  235.     pin = PciRead8 (0, (31<<3) | 7, 0x3D);
  236.     dbgprintf("bus 0 device 31 function 7 pin %d\n", pin-1);
  237. #endif
  238.  
  239. err:
  240.  
  241.     return 0;
  242.  
  243. };
  244.  
  245.