bios.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 <common.h>
  44. #if defined(CONFIG_BIOSEMU)
  45. #include "biosemui.h"
  46. /*----------------------------- Implementation ----------------------------*/
  47. /****************************************************************************
  48. PARAMETERS:
  49. intno - Interrupt number being serviced
  50. REMARKS:
  51. Handler for undefined interrupts.
  52. ****************************************************************************/
  53. static void X86API undefined_intr(int intno)
  54. {
  55. if (BE_rdw(intno * 4 + 2) == BIOS_SEG) {
  56. DB(printf("biosEmu: undefined interrupt %xh called!\n", intno);)
  57. } else
  58. X86EMU_prepareForInt(intno);
  59. }
  60. /****************************************************************************
  61. PARAMETERS:
  62. intno - Interrupt number being serviced
  63. REMARKS:
  64. This function handles the default system BIOS Int 10h (the default is stored
  65. in the Int 42h vector by the system BIOS at bootup). We only need to handle
  66. a small number of special functions used by the BIOS during POST time.
  67. ****************************************************************************/
  68. static void X86API int42(int intno)
  69. {
  70. if (M.x86.R_AH == 0x12 && M.x86.R_BL == 0x32) {
  71. if (M.x86.R_AL == 0) {
  72. /* Enable CPU accesses to video memory */
  73. PM_outpb(0x3c2, PM_inpb(0x3cc) | (u8) 0x02);
  74. return;
  75. } else if (M.x86.R_AL == 1) {
  76. /* Disable CPU accesses to video memory */
  77. PM_outpb(0x3c2, PM_inpb(0x3cc) & (u8) ~ 0x02);
  78. return;
  79. }
  80. #ifdef DEBUG
  81. else {
  82. printf("int42: unknown function AH=0x12, BL=0x32, AL=%#02x\n",
  83. M.x86.R_AL);
  84. }
  85. #endif
  86. }
  87. #ifdef DEBUG
  88. else {
  89. printf("int42: unknown function AH=%#02x, AL=%#02x, BL=%#02x\n",
  90. M.x86.R_AH, M.x86.R_AL, M.x86.R_BL);
  91. }
  92. #endif
  93. }
  94. /****************************************************************************
  95. PARAMETERS:
  96. intno - Interrupt number being serviced
  97. REMARKS:
  98. This function handles the default system BIOS Int 10h. If the POST code
  99. has not yet re-vectored the Int 10h BIOS interrupt vector, we handle this
  100. by simply calling the int42 interrupt handler above. Very early in the
  101. BIOS POST process, the vector gets replaced and we simply let the real
  102. mode interrupt handler process the interrupt.
  103. ****************************************************************************/
  104. static void X86API int10(int intno)
  105. {
  106. if (BE_rdw(intno * 4 + 2) == BIOS_SEG)
  107. int42(intno);
  108. else
  109. X86EMU_prepareForInt(intno);
  110. }
  111. /* Result codes returned by the PCI BIOS */
  112. #define SUCCESSFUL 0x00
  113. #define FUNC_NOT_SUPPORT 0x81
  114. #define BAD_VENDOR_ID 0x83
  115. #define DEVICE_NOT_FOUND 0x86
  116. #define BAD_REGISTER_NUMBER 0x87
  117. #define SET_FAILED 0x88
  118. #define BUFFER_TOO_SMALL 0x89
  119. /****************************************************************************
  120. PARAMETERS:
  121. intno - Interrupt number being serviced
  122. REMARKS:
  123. This function handles the default Int 1Ah interrupt handler for the real
  124. mode code, which provides support for the PCI BIOS functions. Since we only
  125. want to allow the real mode BIOS code *only* see the PCI config space for
  126. its own device, we only return information for the specific PCI config
  127. space that we have passed in to the init function. This solves problems
  128. when using the BIOS to warm boot a secondary adapter when there is an
  129. identical adapter before it on the bus (some BIOS'es get confused in this
  130. case).
  131. ****************************************************************************/
  132. static void X86API int1A(int unused)
  133. {
  134. u16 pciSlot;
  135. #ifdef __KERNEL__
  136. u8 interface, subclass, baseclass;
  137. /* Initialise the PCI slot number */
  138. pciSlot = ((int)_BE_env.vgaInfo.bus << 8) |
  139. ((int)_BE_env.vgaInfo.device << 3) | (int)_BE_env.vgaInfo.function;
  140. #else
  141. /* Fail if no PCI device information has been registered */
  142. if (!_BE_env.vgaInfo.pciInfo)
  143. return;
  144. pciSlot = (u16) (_BE_env.vgaInfo.pciInfo->slot.i >> 8);
  145. #endif
  146. switch (M.x86.R_AX) {
  147. case 0xB101: /* PCI bios present? */
  148. M.x86.R_AL = 0x00; /* no config space/special cycle generation support */
  149. M.x86.R_EDX = 0x20494350; /* " ICP" */
  150. M.x86.R_BX = 0x0210; /* Version 2.10 */
  151. M.x86.R_CL = 0; /* Max bus number in system */
  152. CLEAR_FLAG(F_CF);
  153. break;
  154. case 0xB102: /* Find PCI device */
  155. M.x86.R_AH = DEVICE_NOT_FOUND;
  156. #ifdef __KERNEL__
  157. if (M.x86.R_DX == _BE_env.vgaInfo.VendorID &&
  158. M.x86.R_CX == _BE_env.vgaInfo.DeviceID && M.x86.R_SI == 0) {
  159. #else
  160. if (M.x86.R_DX == _BE_env.vgaInfo.pciInfo->VendorID &&
  161. M.x86.R_CX == _BE_env.vgaInfo.pciInfo->DeviceID &&
  162. M.x86.R_SI == 0) {
  163. #endif
  164. M.x86.R_AH = SUCCESSFUL;
  165. M.x86.R_BX = pciSlot;
  166. }
  167. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  168. break;
  169. case 0xB103: /* Find PCI class code */
  170. M.x86.R_AH = DEVICE_NOT_FOUND;
  171. #ifdef __KERNEL__
  172. pci_read_config_byte(_BE_env.vgaInfo.pcidev, PCI_CLASS_PROG,
  173. &interface);
  174. pci_read_config_byte(_BE_env.vgaInfo.pcidev, PCI_CLASS_DEVICE,
  175. &subclass);
  176. pci_read_config_byte(_BE_env.vgaInfo.pcidev,
  177. PCI_CLASS_DEVICE + 1, &baseclass);
  178. if (M.x86.R_CL == interface && M.x86.R_CH == subclass
  179. && (u8) (M.x86.R_ECX >> 16) == baseclass) {
  180. #else
  181. if (M.x86.R_CL == _BE_env.vgaInfo.pciInfo->Interface &&
  182. M.x86.R_CH == _BE_env.vgaInfo.pciInfo->SubClass &&
  183. (u8) (M.x86.R_ECX >> 16) ==
  184. _BE_env.vgaInfo.pciInfo->BaseClass) {
  185. #endif
  186. M.x86.R_AH = SUCCESSFUL;
  187. M.x86.R_BX = pciSlot;
  188. }
  189. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  190. break;
  191. case 0xB108: /* Read configuration byte */
  192. M.x86.R_AH = BAD_REGISTER_NUMBER;
  193. if (M.x86.R_BX == pciSlot) {
  194. M.x86.R_AH = SUCCESSFUL;
  195. #ifdef __KERNEL__
  196. pci_read_config_byte(_BE_env.vgaInfo.pcidev, M.x86.R_DI,
  197. &M.x86.R_CL);
  198. #else
  199. M.x86.R_CL =
  200. (u8) PCI_accessReg(M.x86.R_DI, 0, PCI_READ_BYTE,
  201. _BE_env.vgaInfo.pciInfo);
  202. #endif
  203. }
  204. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  205. break;
  206. case 0xB109: /* Read configuration word */
  207. M.x86.R_AH = BAD_REGISTER_NUMBER;
  208. if (M.x86.R_BX == pciSlot) {
  209. M.x86.R_AH = SUCCESSFUL;
  210. #ifdef __KERNEL__
  211. pci_read_config_word(_BE_env.vgaInfo.pcidev, M.x86.R_DI,
  212. &M.x86.R_CX);
  213. #else
  214. M.x86.R_CX =
  215. (u16) PCI_accessReg(M.x86.R_DI, 0, PCI_READ_WORD,
  216. _BE_env.vgaInfo.pciInfo);
  217. #endif
  218. }
  219. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  220. break;
  221. case 0xB10A: /* Read configuration dword */
  222. M.x86.R_AH = BAD_REGISTER_NUMBER;
  223. if (M.x86.R_BX == pciSlot) {
  224. M.x86.R_AH = SUCCESSFUL;
  225. #ifdef __KERNEL__
  226. pci_read_config_dword(_BE_env.vgaInfo.pcidev,
  227. M.x86.R_DI, &M.x86.R_ECX);
  228. #else
  229. M.x86.R_ECX =
  230. (u32) PCI_accessReg(M.x86.R_DI, 0, PCI_READ_DWORD,
  231. _BE_env.vgaInfo.pciInfo);
  232. #endif
  233. }
  234. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  235. break;
  236. case 0xB10B: /* Write configuration byte */
  237. M.x86.R_AH = BAD_REGISTER_NUMBER;
  238. if (M.x86.R_BX == pciSlot) {
  239. M.x86.R_AH = SUCCESSFUL;
  240. #ifdef __KERNEL__
  241. pci_write_config_byte(_BE_env.vgaInfo.pcidev,
  242. M.x86.R_DI, M.x86.R_CL);
  243. #else
  244. PCI_accessReg(M.x86.R_DI, M.x86.R_CL, PCI_WRITE_BYTE,
  245. _BE_env.vgaInfo.pciInfo);
  246. #endif
  247. }
  248. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  249. break;
  250. case 0xB10C: /* Write configuration word */
  251. M.x86.R_AH = BAD_REGISTER_NUMBER;
  252. if (M.x86.R_BX == pciSlot) {
  253. M.x86.R_AH = SUCCESSFUL;
  254. #ifdef __KERNEL__
  255. pci_write_config_word(_BE_env.vgaInfo.pcidev,
  256. M.x86.R_DI, M.x86.R_CX);
  257. #else
  258. PCI_accessReg(M.x86.R_DI, M.x86.R_CX, PCI_WRITE_WORD,
  259. _BE_env.vgaInfo.pciInfo);
  260. #endif
  261. }
  262. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  263. break;
  264. case 0xB10D: /* Write configuration dword */
  265. M.x86.R_AH = BAD_REGISTER_NUMBER;
  266. if (M.x86.R_BX == pciSlot) {
  267. M.x86.R_AH = SUCCESSFUL;
  268. #ifdef __KERNEL__
  269. pci_write_config_dword(_BE_env.vgaInfo.pcidev,
  270. M.x86.R_DI, M.x86.R_ECX);
  271. #else
  272. PCI_accessReg(M.x86.R_DI, M.x86.R_ECX, PCI_WRITE_DWORD,
  273. _BE_env.vgaInfo.pciInfo);
  274. #endif
  275. }
  276. CONDITIONAL_SET_FLAG((M.x86.R_AH != SUCCESSFUL), F_CF);
  277. break;
  278. default:
  279. printf("biosEmu/bios.int1a: unknown function AX=%#04x\n",
  280. M.x86.R_AX);
  281. }
  282. }
  283. /****************************************************************************
  284. REMARKS:
  285. This function initialises the BIOS emulation functions for the specific
  286. PCI display device. We insulate the real mode BIOS from any other devices
  287. on the bus, so that it will work correctly thinking that it is the only
  288. device present on the bus (ie: avoiding any adapters present in from of
  289. the device we are trying to control).
  290. ****************************************************************************/
  291. #define BE_constLE_32(v) ((((((v)&0xff00)>>8)|(((v)&0xff)<<8))<<16)|(((((v)&0xff000000)>>8)|(((v)&0x00ff0000)<<8))>>16))
  292. void _BE_bios_init(u32 * intrTab)
  293. {
  294. int i;
  295. X86EMU_intrFuncs bios_intr_tab[256];
  296. for (i = 0; i < 256; ++i) {
  297. intrTab[i] = BE_constLE_32(BIOS_SEG << 16);
  298. bios_intr_tab[i] = undefined_intr;
  299. }
  300. bios_intr_tab[0x10] = int10;
  301. bios_intr_tab[0x1A] = int1A;
  302. bios_intr_tab[0x42] = int42;
  303. bios_intr_tab[0x6D] = int10;
  304. X86EMU_setupIntrFuncs(bios_intr_tab);
  305. }
  306. #endif