0002-vgahooks-optionroms-implement-mxm-3.0-interrupts.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. From 1e7c443d069ef817c4e699bd6675efff4ebddb86 Mon Sep 17 00:00:00 2001
  2. From: Riku Viitanen <riku.viitanen@protonmail.com>
  3. Date: Sat, 10 Feb 2024 21:38:17 +0200
  4. Subject: [PATCH 2/2] vgahooks, optionroms: implement mxm 3.0 interrupts
  5. VGAROMs on MXM graphics cards need certain int15h functions present.
  6. Tested on a HP EliteBook 8560w with coreboot and Quadro 2000M. A warning
  7. is displayed for 30 seconds and performance is nerfed:
  8. ERROR: Valid MXM Structure not found.
  9. POST halted for 30 seconds, P-state limited to P10...
  10. This patch implements the minimum required on this system (and implemented
  11. by the OEM BIOS): functions 0 and 1.
  12. These functions are specific to the MXM 3.0 Software Specification,
  13. earlier versions are not implemented due to lack of hardware. Documentation
  14. for versions 2.1 and 3.0 can be found freely online.
  15. Functions aren't specific to mainboards or GPUs (though some mainboards
  16. could need more functions implemented). The structure is
  17. mainboard-specific and is read from romfile "mxm-30-sis".
  18. It can be extracted from vendor BIOS by running those same interrupts.
  19. I wrote a tool to do it on Linux: https://codeberg.org/Riku_V/mxmdump/
  20. Signed-off-by: Riku Viitanen <riku.viitanen@protonmail.com>
  21. ---
  22. src/optionroms.c | 9 +++++++
  23. src/vgahooks.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
  24. src/vgahooks.h | 9 +++++++
  25. 3 files changed, 87 insertions(+)
  26. create mode 100644 src/vgahooks.h
  27. diff --git a/src/optionroms.c b/src/optionroms.c
  28. index e906ab97..fcce7900 100644
  29. --- a/src/optionroms.c
  30. +++ b/src/optionroms.c
  31. @@ -22,6 +22,7 @@
  32. #include "string.h" // memset
  33. #include "util.h" // get_pnp_offset
  34. #include "tcgbios.h" // tpm_*
  35. +#include "vgahooks.h" // MXM30SIS
  36. static int EnforceChecksum, S3ResumeVga, RunPCIroms;
  37. @@ -463,6 +464,14 @@ vgarom_setup(void)
  38. RunPCIroms = romfile_loadint("etc/pci-optionrom-exec", 2);
  39. ScreenAndDebug = romfile_loadint("etc/screen-and-debug", 1);
  40. + // Load MXM 3.0 System Information Structure
  41. + void *mxm_sis = romfile_loadfile_g("mxm-30-sis", NULL, &malloc_low, 0);
  42. + if (mxm_sis) {
  43. + MXM30SIS = (u32)mxm_sis;
  44. + } else {
  45. + MXM30SIS = 0;
  46. + }
  47. +
  48. // Clear option rom memory
  49. memset((void*)BUILD_ROM_START, 0, rom_get_max() - BUILD_ROM_START);
  50. diff --git a/src/vgahooks.c b/src/vgahooks.c
  51. index 1f149532..a94840b2 100644
  52. --- a/src/vgahooks.c
  53. +++ b/src/vgahooks.c
  54. @@ -18,8 +18,10 @@
  55. #define VH_VIA 1
  56. #define VH_INTEL 2
  57. #define VH_SMI 3
  58. +#define VH_MXM 4
  59. int VGAHookHandlerType VARFSEG;
  60. +u32 MXM30SIS VARFSEG;
  61. static void
  62. handle_155fXX(struct bregs *regs)
  63. @@ -59,6 +61,7 @@ via_155f02(struct bregs *regs)
  64. dprintf(1, "Warning: VGA TV/CRT output type is hardcoded\n");
  65. }
  66. +
  67. static void
  68. via_155f18(struct bregs *regs)
  69. {
  70. @@ -296,6 +299,69 @@ winent_mb6047_setup(struct pci_device *pci)
  71. SmiBootDisplay = 0x02;
  72. }
  73. +/****************************************************************
  74. + * MXM VGA hooks
  75. + ****************************************************************/
  76. +
  77. +// Function 0: Return Specification Support Level
  78. +static void
  79. +mxm_V30_F00(struct bregs *regs)
  80. +{
  81. + regs->ax = 0x005f; // Success
  82. + regs->bl = 0x30; // MXM 3.0
  83. + regs->cx = 0x0003; // Supported Functions
  84. + set_success(regs);
  85. +}
  86. +
  87. +// Function 1: Return a Pointer to the MXM Structure
  88. +static void
  89. +mxm_V30_F01(struct bregs *regs)
  90. +{
  91. + switch (regs->cx) {
  92. + case 0x0030:
  93. + regs->ax = 0x005f; // Success
  94. + regs->es = GET_GLOBAL(MXM30SIS)/16;
  95. + regs->di = GET_GLOBAL(MXM30SIS)%16;
  96. + set_success(regs);
  97. + break;
  98. + default:
  99. + handle_155fXX(regs);
  100. + break;
  101. + }
  102. +}
  103. +
  104. +static void
  105. +mxm_V30(struct bregs *regs)
  106. +{
  107. + switch (regs->bx) {
  108. + case 0xff00: mxm_V30_F00(regs); break;
  109. + case 0xff01: mxm_V30_F01(regs); break;
  110. + default: handle_155fXX(regs); break;
  111. + }
  112. +}
  113. +
  114. +static void
  115. +mxm_155f80(struct bregs *regs)
  116. +{
  117. + // TODO: implement other versions, like 2.1
  118. + mxm_V30(regs);
  119. +}
  120. +
  121. +static void
  122. +mxm_155f(struct bregs *regs)
  123. +{
  124. + switch (regs->al) {
  125. + case 0x80: mxm_155f80(regs); break;
  126. + default: handle_155fXX(regs); break;
  127. + }
  128. +}
  129. +
  130. +void
  131. +mxm_setup(void)
  132. +{
  133. + VGAHookHandlerType = VH_MXM;
  134. +}
  135. +
  136. /****************************************************************
  137. * Entry and setup
  138. ****************************************************************/
  139. @@ -313,6 +379,7 @@ handle_155f(struct bregs *regs)
  140. switch (htype) {
  141. case VH_VIA: via_155f(regs); break;
  142. case VH_INTEL: intel_155f(regs); break;
  143. + case VH_MXM: mxm_155f(regs); break;
  144. default: handle_155fXX(regs); break;
  145. }
  146. }
  147. @@ -352,4 +419,6 @@ vgahook_setup(struct pci_device *pci)
  148. via_setup(pci);
  149. else if (pci->vendor == PCI_VENDOR_ID_INTEL)
  150. intel_setup(pci);
  151. + else if (GET_GLOBAL(MXM30SIS))
  152. + mxm_setup();
  153. }
  154. diff --git a/src/vgahooks.h b/src/vgahooks.h
  155. new file mode 100644
  156. index 00000000..f0c203af
  157. --- /dev/null
  158. +++ b/src/vgahooks.h
  159. @@ -0,0 +1,9 @@
  160. +#ifndef __VGAHOOKS_H
  161. +#define __VGAHOOKS_H
  162. +
  163. +#include "types.h" // u32
  164. +
  165. +extern u32 MXM30SIS;
  166. +
  167. +
  168. +#endif // vgahooks.h
  169. --
  170. 2.43.0