bios.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /****************************************************************************
  2. *
  3. * BIOS emulator and interface
  4. * to Realmode X86 Emulator Library
  5. *
  6. * Copyright (C) 2007 Freescale Semiconductor, Inc. All rights reserved.
  7. * Jason Jin <Jason.jin@freescale.com>
  8. *
  9. * Copyright (C) 1996-1999 SciTech Software, Inc.
  10. *
  11. * ========================================================================
  12. *
  13. * Permission to use, copy, modify, distribute, and sell this software and
  14. * its documentation for any purpose is hereby granted without fee,
  15. * provided that the above copyright notice appear in all copies and that
  16. * both that copyright notice and this permission notice appear in
  17. * supporting documentation, and that the name of the authors not be used
  18. * in advertising or publicity pertaining to distribution of the software
  19. * without specific, written prior permission. The authors makes no
  20. * representations about the suitability of this software for any purpose.
  21. * It is provided "as is" without express or implied warranty.
  22. *
  23. * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  24. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  25. * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  26. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  27. * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  28. * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  29. * PERFORMANCE OF THIS SOFTWARE.
  30. *
  31. * ========================================================================
  32. *
  33. * Language: ANSI C
  34. * Environment: Any
  35. * Developer: Kendall Bennett
  36. *
  37. * Description: Module implementing the BIOS specific functions.
  38. *
  39. * Jason ported this file to u-boot to run the ATI video card
  40. * video BIOS.
  41. *
  42. ****************************************************************************/
  43. #include "biosemui.h"
  44. #if defined(CONFIG_BIOSEMU)
  45. /*----------------------------- Implementation ----------------------------*/
  46. /****************************************************************************
  47. PARAMETERS:
  48. intno - Interrupt number being serviced
  49. REMARKS:
  50. Handler for undefined interrupts.
  51. ****************************************************************************/
  52. static void X86API undefined_intr(int intno)
  53. {
  54. if (BE_rdw(intno * 4 + 2) == BIOS_SEG) {
  55. DB(printf("biosEmu: undefined interrupt %xh called!\n", intno);)
  56. } else
  57. X86EMU_prepareForInt(intno);
  58. }
  59. /****************************************************************************
  60. PARAMETERS:
  61. intno - Interrupt number being serviced
  62. REMARKS:
  63. This function handles the default system BIOS Int 10h (the default is stored
  64. in the Int 42h vector by the system BIOS at bootup). We only need to handle
  65. a small number of special functions used by the BIOS during POST time.
  66. ****************************************************************************/
  67. static void X86API int42(int intno)
  68. {
  69. if (M.x86.R_AH == 0x12 && M.x86.R_BL == 0x32) {
  70. if (M.x86.R_AL == 0) {
  71. /* Enable CPU accesses to video memory */
  72. PM_outpb(0x3c2, PM_inpb(0x3cc) | (u8) 0x02);
  73. return;
  74. } else if (M.x86.R_AL == 1) {
  75. /* Disable CPU accesses to video memory */
  76. PM_outpb(0x3c2, PM_inpb(0x3cc) & (u8) ~ 0x02);
  77. return;
  78. }
  79. #ifdef DEBUG
  80. else {
  81. printf("int42: unknown function AH=0x12, BL=0x32, AL=%#02x\n",
  82. M.x86.R_AL);
  83. }
  84. #endif
  85. }
  86. #ifdef DEBUG
  87. else {
  88. printf("int42: unknown function AH=%#02x, AL=%#02x, BL=%#02x\n",
  89. M.x86.R_AH, M.x86.R_AL, M.x86.R_BL);
  90. }
  91. #endif
  92. }
  93. /****************************************************************************
  94. PARAMETERS:
  95. intno - Interrupt number being serviced
  96. REMARKS:
  97. This function handles the default system BIOS Int 10h. If the POST code
  98. has not yet re-vectored the Int 10h BIOS interrupt vector, we handle this
  99. by simply calling the int42 interrupt handler above. Very early in the
  100. BIOS POST process, the vector gets replaced and we simply let the real
  101. mode interrupt handler process the interrupt.
  102. ****************************************************************************/
  103. static void X86API int10(int intno)
  104. {
  105. if (BE_rdw(intno * 4 + 2) == BIOS_SEG)
  106. int42(intno);
  107. else
  108. X86EMU_prepareForInt(intno);
  109. }
  110. /* Result codes returned by the PCI BIOS */
  111. #define SUCCESSFUL 0x00
  112. #define FUNC_NOT_SUPPORT 0x81
  113. #define BAD_VENDOR_ID 0x83
  114. #define DEVICE_NOT_FOUND 0x86
  115. #define BAD_REGISTER_NUMBER 0x87
  116. #define SET_FAILED 0x88
  117. #define BUFFER_TOO_SMALL 0x89
  118. /****************************************************************************
  119. PARAMETERS:
  120. intno - Interrupt number being serviced
  121. REMARKS:
  122. This function handles the default Int 1Ah interrupt handler for the real
  123. mode code, which provides support for the PCI BIOS functions. Since we only
  124. want to allow the real mode BIOS code *only* see the PCI config space for
  125. its own device, we only return information for the specific PCI config
  126. space that we have passed in to the init function. This solves problems
  127. when using the BIOS to warm boot a secondary adapter when there is an
  128. identical adapter before it on the bus (some BIOS'es get confused in this
  129. case).
  130. ****************************************************************************/
  131. static void X86API int1A(int unused)
  132. {
  133. u16 pciSlot;
  134. #ifdef __KERNEL__
  135. u8 interface, subclass, baseclass;
  136. /* Initialise the PCI slot number */
  137. pciSlot = ((int)_BE_env.vgaInfo.bus << 8) |
  138. ((int)_BE_env.vgaInfo.device << 3) | (int)_BE_env.vgaInfo.function;
  139. #else
  140. /* Fail if no PCI device information has been registered */
  141. if (!_BE_env.vgaInfo.pciInfo)
  142. return;
  143. pciSlot = (u16) (_BE_env.vgaInfo.pciInfo->slot.i >> 8);
  144. #endif
  145. switch (M.x86.R_AX) {
  146. case 0xB101: /* PCI bios present? */
  147. M.x86.R_AL = 0x00; /* no config space/special cycle generation support */
  148. M.x86.R_EDX = 0x20494350; /* " ICP" */
  149. M.x86.R_BX = 0x0210; /* Version 2.10 */
  150. M.x86.R_CL = 0; /* Max bus number in system */
  151. CLEAR_FLAG(F_CF);
  152. break;
  153. case 0xB102: /* Find PCI device */
  154. M.x86.R_AH = DEVICE_NOT_FOUND;
  155. #ifdef __KERNEL__
  156. if (M.x86.R_DX == _BE_env.vgaInfo.VendorID &&
  157. M.x86.R_CX == _BE_env.vgaInfo.DeviceID && M.x86.R_SI == 0) {
  158. #else
  159. if (M.x86.R_DX == _BE_env.vgaInfo.pciInfo->VendorID &&
  160. M.x86.R_CX == _BE_env.vgaInfo.pciInfo->DeviceID &&
  161. M.x86.R_SI == 0) {
  162. #endif
  163. M.x86.R_AH = SUCCESSFUL;
  164. M.x86.R_BX = pciSlot;
  165. }
  166. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  167. break;
  168. case 0xB103: /* Find PCI class code */
  169. M.x86.R_AH = DEVICE_NOT_FOUND;
  170. #ifdef __KERNEL__
  171. pci_read_config_byte(_BE_env.vgaInfo.pcidev, PCI_CLASS_PROG,
  172. &interface);
  173. pci_read_config_byte(_BE_env.vgaInfo.pcidev, PCI_CLASS_DEVICE,
  174. &subclass);
  175. pci_read_config_byte(_BE_env.vgaInfo.pcidev,
  176. PCI_CLASS_DEVICE + 1, &baseclass);
  177. if (M.x86.R_CL == interface && M.x86.R_CH == subclass
  178. && (u8) (M.x86.R_ECX >> 16) == baseclass) {
  179. #else
  180. if (M.x86.R_CL == _BE_env.vgaInfo.pciInfo->Interface &&
  181. M.x86.R_CH == _BE_env.vgaInfo.pciInfo->SubClass &&
  182. (u8) (M.x86.R_ECX >> 16) ==
  183. _BE_env.vgaInfo.pciInfo->BaseClass) {
  184. #endif
  185. M.x86.R_AH = SUCCESSFUL;
  186. M.x86.R_BX = pciSlot;
  187. }
  188. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  189. break;
  190. case 0xB108: /* Read configuration byte */
  191. M.x86.R_AH = BAD_REGISTER_NUMBER;
  192. if (M.x86.R_BX == pciSlot) {
  193. M.x86.R_AH = SUCCESSFUL;
  194. #ifdef __KERNEL__
  195. pci_read_config_byte(_BE_env.vgaInfo.pcidev, M.x86.R_DI,
  196. &M.x86.R_CL);
  197. #else
  198. M.x86.R_CL =
  199. (u8) PCI_accessReg(M.x86.R_DI, 0, PCI_READ_BYTE,
  200. _BE_env.vgaInfo.pciInfo);
  201. #endif
  202. }
  203. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  204. break;
  205. case 0xB109: /* Read configuration word */
  206. M.x86.R_AH = BAD_REGISTER_NUMBER;
  207. if (M.x86.R_BX == pciSlot) {
  208. M.x86.R_AH = SUCCESSFUL;
  209. #ifdef __KERNEL__
  210. pci_read_config_word(_BE_env.vgaInfo.pcidev, M.x86.R_DI,
  211. &M.x86.R_CX);
  212. #else
  213. M.x86.R_CX =
  214. (u16) PCI_accessReg(M.x86.R_DI, 0, PCI_READ_WORD,
  215. _BE_env.vgaInfo.pciInfo);
  216. #endif
  217. }
  218. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  219. break;
  220. case 0xB10A: /* Read configuration dword */
  221. M.x86.R_AH = BAD_REGISTER_NUMBER;
  222. if (M.x86.R_BX == pciSlot) {
  223. M.x86.R_AH = SUCCESSFUL;
  224. #ifdef __KERNEL__
  225. pci_read_config_dword(_BE_env.vgaInfo.pcidev,
  226. M.x86.R_DI, &M.x86.R_ECX);
  227. #else
  228. M.x86.R_ECX =
  229. (u32) PCI_accessReg(M.x86.R_DI, 0, PCI_READ_DWORD,
  230. _BE_env.vgaInfo.pciInfo);
  231. #endif
  232. }
  233. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  234. break;
  235. case 0xB10B: /* Write configuration byte */
  236. M.x86.R_AH = BAD_REGISTER_NUMBER;
  237. if (M.x86.R_BX == pciSlot) {
  238. M.x86.R_AH = SUCCESSFUL;
  239. #ifdef __KERNEL__
  240. pci_write_config_byte(_BE_env.vgaInfo.pcidev,
  241. M.x86.R_DI, M.x86.R_CL);
  242. #else
  243. PCI_accessReg(M.x86.R_DI, M.x86.R_CL, PCI_WRITE_BYTE,
  244. _BE_env.vgaInfo.pciInfo);
  245. #endif
  246. }
  247. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  248. break;
  249. case 0xB10C: /* Write configuration word */
  250. M.x86.R_AH = BAD_REGISTER_NUMBER;
  251. if (M.x86.R_BX == pciSlot) {
  252. M.x86.R_AH = SUCCESSFUL;
  253. #ifdef __KERNEL__
  254. pci_write_config_word(_BE_env.vgaInfo.pcidev,
  255. M.x86.R_DI, M.x86.R_CX);
  256. #else
  257. PCI_accessReg(M.x86.R_DI, M.x86.R_CX, PCI_WRITE_WORD,
  258. _BE_env.vgaInfo.pciInfo);
  259. #endif
  260. }
  261. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  262. break;
  263. case 0xB10D: /* Write configuration dword */
  264. M.x86.R_AH = BAD_REGISTER_NUMBER;
  265. if (M.x86.R_BX == pciSlot) {
  266. M.x86.R_AH = SUCCESSFUL;
  267. #ifdef __KERNEL__
  268. pci_write_config_dword(_BE_env.vgaInfo.pcidev,
  269. M.x86.R_DI, M.x86.R_ECX);
  270. #else
  271. PCI_accessReg(M.x86.R_DI, M.x86.R_ECX, PCI_WRITE_DWORD,
  272. _BE_env.vgaInfo.pciInfo);
  273. #endif
  274. }
  275. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  276. break;
  277. default:
  278. printf("biosEmu/bios.int1a: unknown function AX=%#04x\n",
  279. M.x86.R_AX);
  280. }
  281. }
  282. /****************************************************************************
  283. REMARKS:
  284. This function initialises the BIOS emulation functions for the specific
  285. PCI display device. We insulate the real mode BIOS from any other devices
  286. on the bus, so that it will work correctly thinking that it is the only
  287. device present on the bus (ie: avoiding any adapters present in from of
  288. the device we are trying to control).
  289. ****************************************************************************/
  290. #define BE_constLE_32(v) ((((((v)&0xff00)>>8)|(((v)&0xff)<<8))<<16)|(((((v)&0xff000000)>>8)|(((v)&0x00ff0000)<<8))>>16))
  291. void _BE_bios_init(u32 * intrTab)
  292. {
  293. int i;
  294. X86EMU_intrFuncs bios_intr_tab[256];
  295. for (i = 0; i < 256; ++i) {
  296. intrTab[i] = BE_constLE_32(BIOS_SEG << 16);
  297. bios_intr_tab[i] = undefined_intr;
  298. }
  299. bios_intr_tab[0x10] = int10;
  300. bios_intr_tab[0x1A] = int1A;
  301. bios_intr_tab[0x42] = int42;
  302. bios_intr_tab[0x6D] = int10;
  303. X86EMU_setupIntrFuncs(bios_intr_tab);
  304. }
  305. #endif