| 1 | #include <stdint.h> |
| 2 | #include <stddef.h> |
| 3 | #include <drivers/gop.h> |
| 4 | #include <drivers/edid.h> |
| 5 | #include <mm/pmm.h> |
| 6 | #include <lib/misc.h> |
| 7 | #include <lib/libc.h> |
| 8 | #include <lib/print.h> |
| 9 | |
| 10 | #if defined (BIOS) |
| 11 | |
| 12 | #include <lib/real.h> |
| 13 | |
| 14 | struct edid_info_struct *get_edid_info(void) { |
| 15 | static struct edid_info_struct *buf = NULL; |
| 16 | |
| 17 | if (buf == NULL) |
| 18 | buf = conv_mem_alloc(sizeof(struct edid_info_struct)); |
| 19 | |
| 20 | struct rm_regs r = {0}; |
| 21 | |
| 22 | r.eax = 0x4f15; |
| 23 | r.ebx = 0x0001; |
| 24 | r.edi = (uint32_t)rm_off(buf); |
| 25 | r.ds = (uint32_t)rm_seg(buf); |
| 26 | r.es = r.ds; |
| 27 | rm_int(0x10, &r, &r); |
| 28 | |
| 29 | if ((r.eax & 0x00ff) != 0x4f) |
| 30 | goto fail; |
| 31 | if ((r.eax & 0xff00) != 0) |
| 32 | goto fail; |
| 33 | |
| 34 | for (size_t i = 0; i < sizeof(struct edid_info_struct); i++) |
| 35 | if (((uint8_t *)buf)[i] != 0) |
| 36 | goto success; |
| 37 | |
| 38 | fail: |
| 39 | printv("edid: Could not fetch EDID data.\n"); |
| 40 | return NULL; |
| 41 | |
| 42 | success: |
| 43 | printv("edid: Success.\n"); |
| 44 | return buf; |
| 45 | } |
| 46 | |
| 47 | #endif |
| 48 | |
| 49 | #if defined (UEFI) |
| 50 | |
| 51 | #include <efi.h> |
| 52 | |
| 53 | struct edid_info_struct *get_edid_info(EFI_HANDLE gop_handle) { |
| 54 | struct edid_info_struct *buf = ext_mem_alloc(sizeof(struct edid_info_struct)); |
| 55 | |
| 56 | EFI_STATUS status; |
| 57 | |
| 58 | EFI_EDID_ACTIVE_PROTOCOL *edid = NULL; |
| 59 | EFI_GUID edid_guid = EFI_EDID_ACTIVE_PROTOCOL_GUID; |
| 60 | |
| 61 | status = gBS->HandleProtocol(gop_handle, &edid_guid, (void **)&edid); |
| 62 | |
| 63 | if (status) |
| 64 | goto fail; |
| 65 | |
| 66 | if (edid->SizeOfEdid < sizeof(struct edid_info_struct)) |
| 67 | goto fail; |
| 68 | |
| 69 | memcpy(buf, edid->Edid, sizeof(struct edid_info_struct)); |
| 70 | |
| 71 | for (size_t i = 0; i < sizeof(struct edid_info_struct); i++) |
| 72 | if (((uint8_t *)buf)[i] != 0) |
| 73 | goto success; |
| 74 | |
| 75 | fail: |
| 76 | pmm_free(buf, sizeof(struct edid_info_struct)); |
| 77 | printv("edid: Could not fetch EDID data.\n"); |
| 78 | return NULL; |
| 79 | |
| 80 | success: |
| 81 | printv("edid: Success.\n"); |
| 82 | return buf; |
| 83 | } |
| 84 | |
| 85 | #endif |