Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

345 lines
11 KiB

  1. /******************************************************************************
  2. * name: cnvinfo.c
  3. *
  4. * description: Routines to convert old mga.inf format to the current
  5. * revision
  6. *
  7. * designed: Christian Toutant
  8. * last modified: $Author:
  9. *
  10. * version: $Id:
  11. *
  12. *
  13. * char * mtxConvertMgaInf( char *)
  14. *
  15. ******************************************************************************/
  16. #include "switches.h"
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include "bind.h"
  20. #include "defbind.h"
  21. #include "defoldv.h"
  22. /* Prototypes */
  23. word findInfoPrec(header *hdr, word i);
  24. void cnvBrdInfo_101(general_info *dst, general_info_101 *src);
  25. word sizeOfBoard(header *hdr, word i);
  26. char *convertRev101(char *dst, char *src);
  27. char *mtxConvertMgaInf( char *inf );
  28. #ifdef WINDOWS_NT
  29. #if defined(ALLOC_PRAGMA)
  30. #pragma alloc_text(PAGE,findInfoPrec)
  31. #pragma alloc_text(PAGE,cnvBrdInfo_101)
  32. #pragma alloc_text(PAGE,sizeOfBoard)
  33. #pragma alloc_text(PAGE,convertRev101)
  34. #pragma alloc_text(PAGE,mtxConvertMgaInf)
  35. #endif
  36. #endif /* #ifdef WINDOWS_NT */
  37. extern char DefaultVidset[];
  38. # define GENERAL_INFO(h, i) ( (general_info *) ( (char *)h + ((header *)h)->BoardPtr[i] ) )
  39. # define GENERAL_INFO101(h, i) ( (general_info_101 *) ( (char *)h + ((header *)h)->BoardPtr[i] ) )
  40. #ifdef WINDOWS_NT
  41. extern ULONG ulNewInfoSize;
  42. extern PVOID pMgaDeviceExtension;
  43. PVOID AllocateSystemMemory(ULONG NumberOfBytes);
  44. #endif /* #ifdef WINDOWS_NT */
  45. /*----------------------------------------------------------------------------
  46. | name: findInfoPrec
  47. |
  48. | description: check if a previous board pointer have the same offset
  49. |
  50. |
  51. | designed: Christian Toutant, august 26, 1993
  52. | last modified:
  53. |
  54. |
  55. | parameters: header *hdr header for search
  56. | word i current board pointer
  57. | modifies: none
  58. | calls:
  59. | returns: word index of previous board whit the same offset
  60. | or NUMBER_BOARD_MAX if no found.
  61. |
  62. -----------------------------------------------------------------------------*/
  63. word findInfoPrec(header *hdr, word i)
  64. {
  65. word j;
  66. for (j = 0; j < i; j++)
  67. if (hdr->BoardPtr[i] == hdr->BoardPtr[j]) return j;
  68. return NUMBER_BOARD_MAX;
  69. }
  70. /*----------------------------------------------------------------------------
  71. | name: cnvBrdInfo_101
  72. |
  73. | description: convert general_info ver 101 to general_info ver 102 (current)
  74. |
  75. |
  76. | designed: Christian Toutant, august 26, 1993
  77. | last modified:
  78. |
  79. |
  80. | parameters: general_info *dst pointer to destination general_info (v.102)
  81. | general_info_101 *src pointer to source general_info (v.101)
  82. | modifies: none
  83. | calls:
  84. | returns: bool
  85. |
  86. |note : This function must be change when we pass to ver 103. The conversion
  87. | will be from v. 101 to v. 103.
  88. -----------------------------------------------------------------------------*/
  89. void cnvBrdInfo_101(general_info *dst, general_info_101 *src)
  90. {
  91. word i, j;
  92. Vidparm_101 *srcVidParm;
  93. Vidparm *dstVidParm;
  94. dst->MapAddress = src->MapAddress ;
  95. dst->BitOperation8_16 = src->BitOperation8_16 ;
  96. dst->DmaEnable = src->DmaEnable ;
  97. dst->DmaChannel = src->DmaChannel ;
  98. dst->DmaType = src->DmaType ;
  99. dst->DmaXferWidth = src->DmaXferWidth ;
  100. dst->NumVidparm = src->NumVidparm ;
  101. strncpy(dst->MonitorName, src->MonitorName, 64);
  102. for (i = 0; i < NUMBER_OF_RES; i++)
  103. dst->MonitorSupport[i] = src->MonitorSupport[i];
  104. srcVidParm = (Vidparm_101 *)(((char *)src) + sizeof(general_info_101));
  105. dstVidParm = (Vidparm*)(((char *)dst) + sizeof(general_info));
  106. for (i = 0; i < src->NumVidparm; i++)
  107. {
  108. dstVidParm[i].Resolution = srcVidParm[i].Resolution;
  109. dstVidParm[i].PixWidth = srcVidParm[i].PixWidth;
  110. for (j = 0; j < 3; j++)
  111. {
  112. dstVidParm[i].VidsetPar[j].PixClock = srcVidParm[i].VidsetPar[j].PixClock;
  113. dstVidParm[i].VidsetPar[j].HDisp = srcVidParm[i].VidsetPar[j].HDisp ;
  114. dstVidParm[i].VidsetPar[j].HFPorch = srcVidParm[i].VidsetPar[j].HFPorch ;
  115. dstVidParm[i].VidsetPar[j].HSync = srcVidParm[i].VidsetPar[j].HSync ;
  116. dstVidParm[i].VidsetPar[j].HBPorch = srcVidParm[i].VidsetPar[j].HBPorch ;
  117. dstVidParm[i].VidsetPar[j].HOvscan = srcVidParm[i].VidsetPar[j].HOvscan ;
  118. dstVidParm[i].VidsetPar[j].VDisp = srcVidParm[i].VidsetPar[j].VDisp ;
  119. dstVidParm[i].VidsetPar[j].VFPorch = srcVidParm[i].VidsetPar[j].VFPorch ;
  120. dstVidParm[i].VidsetPar[j].VSync = srcVidParm[i].VidsetPar[j].VSync ;
  121. dstVidParm[i].VidsetPar[j].VBPorch = srcVidParm[i].VidsetPar[j].VBPorch ;
  122. dstVidParm[i].VidsetPar[j].VOvscan = srcVidParm[i].VidsetPar[j].VOvscan ;
  123. dstVidParm[i].VidsetPar[j].OvscanEnable = srcVidParm[i].VidsetPar[j].OvscanEnable;
  124. dstVidParm[i].VidsetPar[j].InterlaceEnable= srcVidParm[i].VidsetPar[j].InterlaceEnable;
  125. dstVidParm[i].VidsetPar[j].HsyncPol = 0;
  126. dstVidParm[i].VidsetPar[j].VsyncPol = 0;
  127. }
  128. }
  129. }
  130. /*----------------------------------------------------------------------------
  131. | name: sizeOfBoard
  132. |
  133. | description: calculate the size of memory for one board (without the
  134. | size of the header).
  135. |
  136. |
  137. | designed: Christian Toutant, august 26, 1993
  138. | last modified:
  139. |
  140. |
  141. | parameters: header *hdr header info
  142. | word index of the board to calculate.
  143. | modifies: none
  144. | calls:
  145. | returns: word size needed for the ith board or 0 if no
  146. | board.
  147. |
  148. |note : This function must be change when we pass to ver 103. The size
  149. | will be for v. 103.
  150. |
  151. -----------------------------------------------------------------------------*/
  152. word sizeOfBoard(header *hdr, word i)
  153. {
  154. word sizeBoard, j;
  155. /* if no board, return size of 0 */
  156. if ( hdr->BoardPtr[i] == (short)-1 ) return 0;
  157. /* if a board farther have the same address data, return the
  158. good size only for the last one and 0 for the other
  159. */
  160. for (j = i + 1 ; j < NUMBER_BOARD_MAX; j++)
  161. if (hdr->BoardPtr[i] == hdr->BoardPtr[j]) return 0;
  162. /* calculate the size of this board */
  163. sizeBoard = sizeof(general_info);
  164. sizeBoard += sizeof(Vidparm) * GENERAL_INFO101(hdr, i)->NumVidparm;
  165. return sizeBoard;
  166. }
  167. /*----------------------------------------------------------------------------
  168. | name: convertRev101
  169. |
  170. | description: convert from mga.inf v.101 to mga.inf v.102
  171. |
  172. |
  173. | designed: Christian Toutant, august 26, 1993
  174. | last modified:
  175. |
  176. |
  177. | parameters: char *dst pointer to memory destination for new mga.inf
  178. | enough must be allocated.
  179. | char *src pointer to the mga.inf v.101
  180. | modifies: none
  181. | calls:
  182. | returns: pointer to the destination mga.inf pointer
  183. |
  184. |note : This function must be change when we pass to ver 103. The conversion
  185. | will be from v. 101 to v. 103.
  186. |
  187. -----------------------------------------------------------------------------*/
  188. char *convertRev101(char *dst, char *src)
  189. {
  190. word i, j, brdPtr;
  191. header *srcHdr, *dstHdr;
  192. srcHdr = (header *)src;
  193. dstHdr = (header *)dst;
  194. brdPtr = sizeof(header);
  195. for (i = 0; i < NUMBER_BOARD_MAX; i ++)
  196. {
  197. if (srcHdr->BoardPtr[i] == (short)-1)
  198. dstHdr->BoardPtr[i] = -1;
  199. else
  200. {
  201. if ( (j = findInfoPrec(srcHdr, i)) < NUMBER_BOARD_MAX )
  202. dstHdr->BoardPtr[i] = dstHdr->BoardPtr[j];
  203. else
  204. {
  205. dstHdr->BoardPtr[i] = brdPtr;
  206. cnvBrdInfo_101( GENERAL_INFO(dstHdr, i),GENERAL_INFO101(srcHdr, i) );
  207. brdPtr += sizeOfBoard(srcHdr, i);
  208. }
  209. }
  210. }
  211. return dst;
  212. }
  213. /*----------------------------------------------------------------------------
  214. | name: mtxConvertMgaInf
  215. |
  216. | description: convert a old mga.inf definition to the current one.
  217. | this function allocate memory for the new mga.inf and
  218. | free the memory of the old one.
  219. |
  220. |
  221. | designed: Christian Toutant, august 26, 1993
  222. | last modified:
  223. |
  224. |
  225. | parameters: char *inf pointer to the old mga.inf
  226. | modifies: free memory pointed by inf.
  227. | calls:
  228. | returns: pointer to the new mga.inf or 0 if error in conversion.
  229. | note: the memory pointer by inf is free also if an error
  230. | occur.
  231. |
  232. -----------------------------------------------------------------------------*/
  233. char *mtxConvertMgaInf( char *inf )
  234. {
  235. char *newInfo;
  236. word size_newInfo, i;
  237. word rev;
  238. header *hdr = (header *)inf;
  239. rev = hdr->Revision;
  240. size_newInfo = sizeof(header);
  241. for (i = 0; i < NUMBER_BOARD_MAX; i ++)
  242. {
  243. switch(rev)
  244. {
  245. case 101:
  246. if (
  247. (hdr->BoardPtr[i] != -1) &&
  248. (GENERAL_INFO101(hdr, i)->NumVidparm < 0)
  249. )
  250. {
  251. #ifndef WINDOWS_NT
  252. /* In Windows NT, inf points to RequestPacket.InputBuffer:
  253. don't free it! */
  254. free ( inf );
  255. #endif
  256. return DefaultVidset;
  257. }
  258. size_newInfo += sizeOfBoard(hdr, i);
  259. break;
  260. default:
  261. #ifndef WINDOWS_NT
  262. /* In Windows NT, inf points to RequestPacket.InputBuffer:
  263. don't free it! */
  264. free( inf );
  265. #endif
  266. return DefaultVidset;
  267. }
  268. }
  269. #ifdef WINDOWS_NT
  270. if ((newInfo = (PUCHAR)AllocateSystemMemory(size_newInfo)) == (PUCHAR)NULL)
  271. {
  272. /* Not enough memory */
  273. return DefaultVidset;
  274. }
  275. #else
  276. if ( (newInfo = (char *)malloc(size_newInfo)) == (char *)0 )
  277. {
  278. /* Not enough memory */
  279. free( inf );
  280. return DefaultVidset;
  281. }
  282. #endif /* #ifdef WINDOWS_NT */
  283. hdr = (header *)newInfo;
  284. hdr->Revision = (short)VERSION_NUMBER;
  285. strncpy(hdr->IdString, ((header *)inf)->IdString, 32);
  286. switch(rev)
  287. {
  288. case 101:
  289. newInfo = convertRev101(newInfo, inf);
  290. break;
  291. default:
  292. #ifdef WINDOWS_NT
  293. VideoPortReleaseBuffer(pMgaDeviceExtension, newInfo);
  294. #else
  295. free(newInfo);
  296. #endif
  297. return DefaultVidset;
  298. break;
  299. }
  300. #ifdef WINDOWS_NT
  301. /* We want to know the size of our new buffer in IOCTL_VIDEO_MTX_INITIALIZE_MGA */
  302. ulNewInfoSize = (ULONG) size_newInfo;
  303. #endif
  304. #ifndef WINDOWS_NT
  305. /* In Windows NT, inf points to RequestPacket.InputBuffer: don't free it! */
  306. free ( inf );
  307. #endif
  308. return newInfo;
  309. }