bios.c 11 KB

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