Subversion Repositories Kolibri OS

Rev

Rev 1500 | 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. /*
  55.     buffer.Pointer = &info;
  56.     memset(&info, 0, sizeof(ACPI_DEVICE_INFO));
  57.     status = AcpiGetObjectInfo(obj, &buffer.Pointer);
  58.  
  59.     if (ACPI_SUCCESS (status))
  60.     {
  61.         dbgprintf (" HID: %s, ADR: %x %x, Status: %x",
  62.         info.HardwareId.String,
  63.         (UINT32)(info.Address>>32),(UINT32)info.Address,
  64.         info.CurrentStatus);
  65.     };
  66. */
  67.  
  68.     dbgprintf("\n");
  69.     counter++;
  70.  
  71.         return AE_OK;
  72. }
  73.  
  74. prt_walk_table(ACPI_BUFFER *prt)
  75. {
  76.     ACPI_PCI_ROUTING_TABLE *entry;
  77.     char *prtptr;
  78.  
  79.     /* First check to see if there is a table to walk. */
  80.     if (prt == NULL || prt->Pointer == NULL)
  81.         return;
  82.  
  83.     /* Walk the table executing the handler function for each entry. */
  84.     prtptr = prt->Pointer;
  85.     entry = (ACPI_PCI_ROUTING_TABLE *)prtptr;
  86.     while (entry->Length != 0)
  87.     {
  88.  
  89.         dbgprintf("adress: %x %x  ", (u32_t)(entry->Address>>32),
  90.                   (u32_t)entry->Address);
  91.         dbgprintf("pin: %d  index: %d  source: %s\n",
  92.                    entry->Pin,
  93.                    entry->SourceIndex,
  94.                    entry->Source);
  95.  
  96. //      handler(entry, arg);
  97.         prtptr += entry->Length;
  98.         entry = (ACPI_PCI_ROUTING_TABLE *)prtptr;
  99.     }
  100. }
  101.  
  102.  
  103.  
  104.  
  105. u32_t drvEntry(int action, char *cmdline)
  106. {
  107.     u32_t retval;
  108.  
  109.     int i;
  110.  
  111.     if(action != 1)
  112.         return 0;
  113.  
  114.       ACPI_STATUS status;
  115.  
  116.       status = AcpiInitializeSubsystem();
  117.       if (status != AE_OK) {
  118.             dbgprintf("AcpiInitializeSubsystem failed (%s)\n",
  119.                        AcpiFormatException(status));
  120.             goto err;
  121.       }
  122.  
  123.       status = AcpiInitializeTables(NULL, 0, TRUE);
  124.       if (status != AE_OK) {
  125.             dbgprintf("AcpiInitializeTables failed (%s)\n",
  126.                        AcpiFormatException(status));
  127.             goto err;
  128.       }
  129.  
  130.       status = AcpiLoadTables();
  131.       if (status != AE_OK) {
  132.             dbgprintf("AcpiLoadTables failed (%s)\n",
  133.                        AcpiFormatException(status));
  134.             goto err;
  135.       }
  136.  
  137.     u32_t mode = ACPI_FULL_INITIALIZATION;
  138.  
  139.     status = AcpiEnableSubsystem(mode);
  140.     if (status != AE_OK) {
  141.         dbgprintf("AcpiEnableSubsystem failed (%s)\n",
  142.             AcpiFormatException(status));
  143.         goto err;
  144.     }
  145.  
  146.     status = AcpiInitializeObjects (ACPI_FULL_INITIALIZATION);
  147.     if (ACPI_FAILURE (status))
  148.     {
  149.         dbgprintf("AcpiInitializeObjects failed (%s)\n",
  150.             AcpiFormatException(status));
  151.         goto err;
  152.     }
  153.  
  154.     AcpiWalkNamespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 4,
  155.                       get_device_by_hid_callback, NULL, NULL, NULL);
  156.  
  157. #if 0
  158.  
  159.     ACPI_OBJECT obj;
  160.     ACPI_HANDLE bus_handle;
  161.     ACPI_HANDLE pci_root;
  162.  
  163.     status = AcpiGetHandle(0, "\\_SB_", &bus_handle);
  164.     dbgprintf("system bus handle %x\n", bus_handle);
  165.  
  166.     status = AcpiGetHandle(bus_handle, "PCI0", &pci_root);
  167.  
  168.     if (status != AE_OK) {
  169.         dbgprintf("AcpiGetHandle failed (%s)\n",
  170.             AcpiFormatException(status));
  171.         goto err;
  172.     }
  173.  
  174.     dbgprintf("pci root handle %x\n\n", pci_root);
  175.  
  176.     ACPI_BUFFER prt_buffer;
  177.  
  178.     prt_buffer.Length = ACPI_ALLOCATE_BUFFER;
  179.     prt_buffer.Pointer = NULL;
  180.  
  181.     status = AcpiGetIrqRoutingTable(pci_root, &prt_buffer);
  182.  
  183.     if (status != AE_OK) {
  184.         dbgprintf("AcpiGetIrqRoutingTable failed (%s)\n",
  185.             AcpiFormatException(status));
  186.         goto err;
  187.     }
  188.  
  189.     prt_walk_table(&prt_buffer);
  190.  
  191.  
  192.     ACPI_OBJECT arg = { ACPI_TYPE_INTEGER };
  193.     ACPI_OBJECT_LIST arg_list = { 1, &arg };
  194.  
  195.     arg.Integer.Value = ACPI_IRQ_MODEL_IOAPIC;
  196.  
  197.     dbgprintf("\nset ioapic mode\n\n");
  198.  
  199.     status = AcpiEvaluateObject(NULL, "\\_PIC", &arg_list, NULL);
  200.  
  201.     if (ACPI_FAILURE(status)) {
  202.         dbgprintf("AcpiEvaluateObject failed (%s)\n",
  203.             AcpiFormatException(status));
  204.  //       goto err;
  205.     }
  206.  
  207.  
  208.     status = AcpiGetIrqRoutingTable(pci_root, &prt_buffer);
  209.  
  210.     if (status != AE_OK) {
  211.         dbgprintf("AcpiGetIrqRoutingTable failed (%s)\n",
  212.             AcpiFormatException(status));
  213.         goto err;
  214.     }
  215.  
  216.     prt_walk_table(&prt_buffer);
  217.  
  218.     u8_t pin = PciRead8 (0, (31<<3) | 1, 0x3D);
  219.     dbgprintf("bus 0 device 31 function 1 pin %d\n", pin-1);
  220.  
  221.     pin = PciRead8 (0, (31<<3) | 2, 0x3D);
  222.     dbgprintf("bus 0 device 31 function 2 pin %d\n", pin-1);
  223.  
  224.     pin = PciRead8 (0, (31<<3) | 3, 0x3D);
  225.     dbgprintf("bus 0 device 31 function 3 pin %d\n", pin-1);
  226.  
  227.     pin = PciRead8 (0, (31<<3) | 4, 0x3D);
  228.     dbgprintf("bus 0 device 31 function 4 pin %d\n", pin-1);
  229.  
  230.     pin = PciRead8 (0, (31<<3) | 5, 0x3D);
  231.     dbgprintf("bus 0 device 31 function 5 pin %d\n", pin-1);
  232.  
  233.     pin = PciRead8 (0, (31<<3) | 6, 0x3D);
  234.     dbgprintf("bus 0 device 31 function 6 pin %d\n", pin-1);
  235.  
  236.     pin = PciRead8 (0, (31<<3) | 7, 0x3D);
  237.     dbgprintf("bus 0 device 31 function 7 pin %d\n", pin-1);
  238. #endif
  239.  
  240. err:
  241.  
  242.     return 0;
  243.  
  244. };
  245.  
  246.