Leaked source code of windows server 2003
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.

1163 lines
44 KiB

  1. /*
  2. * $Log: V:/Flite/archives/TrueFFS5/Src/DOCSYS.C_V $
  3. *
  4. * Rev 1.16 Apr 15 2002 08:30:30 oris
  5. * Added support for USE_TFFS_COPY compilation flag. This flag is used by bios driver a Boot SDK in order to improove performance.
  6. *
  7. * Rev 1.15 Apr 15 2002 07:35:56 oris
  8. * Reorganized for final release.
  9. *
  10. * Rev 1.14 Jan 28 2002 21:24:10 oris
  11. * Removed static prefix to all runtime configurable memory access routines.
  12. * Replaced FLFlash argument with DiskOnChip memory base pointer.
  13. * Changed interface of write and set routines (those that handle more then 8/16 bits) so that instead of FLFlash record they receive the DiskOnChip memory window base pointer and offset (2 separated arguments). The previous implementation did not support address shifting properly.
  14. * Changed tffscpy and tffsset to flcpy and flset when flUse8bit equals 0.
  15. * Changed memWinowSize to memWindowSize
  16. *
  17. * Rev 1.13 Jan 17 2002 22:59:30 oris
  18. * Completely revised, to support runtime customization and all M-Systems
  19. * DiskOnChip devices.
  20. *
  21. * Rev 1.12 Sep 25 2001 15:35:02 oris
  22. * Restored to OSAK 4.3 implementation.
  23. *
  24. */
  25. /************************************************************************/
  26. /* */
  27. /* FAT-FTL Lite Software Development Kit */
  28. /* Copyright (C) M-Systems Ltd. 1995-2001 */
  29. /* */
  30. /************************************************************************/
  31. #include "docsys.h"
  32. /*
  33. * Uncomment the FL_INIT_MMU_PAGES definition for:
  34. *
  35. * Initializes the first and last byte of the given buffer.
  36. * When the user buffer resides on separated memory pages the read
  37. * operation may cause a page fault. Some CPU's return from a page
  38. * fault (after loading the new page) and reread the bytes that caused
  39. * the page fault from the new loaded page. In order to prevent such a
  40. * case the first and last bytes of the buffer are written.
  41. *
  42. */
  43. #define FL_INIT_MMU_PAGES
  44. #ifndef FL_NO_USE_FUNC
  45. /*********************************************************/
  46. /* Report DiskOnChip Memory size */
  47. /*********************************************************/
  48. /*----------------------------------------------------------------------
  49. f l D o c M e m W i n S i z e N o S h i f t
  50. This routine is called from MTD to quary the size of the DiskOnChip
  51. memory window for none shifted DiskOnChip.
  52. ------------------------------------------------------------------------*/
  53. dword flDocMemWinSizeNoShift(void)
  54. {
  55. return 0x2000;
  56. }
  57. /*----------------------------------------------------------------------
  58. f l D o c M e m W i n S i z e S i n g l e S h i f t
  59. This routine is called from MTD to quary the size of the DiskOnChip
  60. memory window for DiskOnChip connected with a single addres shift.
  61. ------------------------------------------------------------------------*/
  62. dword flDocMemWinSizeSingleShift(void)
  63. {
  64. return 0x4000;
  65. }
  66. /*----------------------------------------------------------------------
  67. f l D o c M e m W i n S i z e D o u b l e S h i f t
  68. This routine is called from MTD to quary the size of the DiskOnChip
  69. memory window for DiskOnChip connected with a double addres shift.
  70. ------------------------------------------------------------------------*/
  71. dword flDocMemWinSizeDoubleShift(void)
  72. {
  73. return 0x8000;
  74. }
  75. /*********************************************************/
  76. /* Write 16 bits to DiskOnChip memory window */
  77. /*********************************************************/
  78. /*----------------------------------------------------------------------
  79. f l W r i t e 1 6 b i t D u m m y
  80. Dummy routine - write 16-bits to memory (does nothing).
  81. ------------------------------------------------------------------------*/
  82. void flWrite16bitDummy(volatile byte FAR0 * win, word offset,Reg16bitType val)
  83. {
  84. DEBUG_PRINT(("Wrong customization - 16bit write was used with no implemented.\r\n"));
  85. }
  86. /*----------------------------------------------------------------------
  87. f l W r i t e 1 6 b i t U s i n g 1 6 b i t s N o S h i f t
  88. Note : offset must be 16-bits aligned.
  89. Write 16-bit Using 16-bits operands with no address shifted.
  90. ------------------------------------------------------------------------*/
  91. void flWrite16bitUsing16bitsNoShift(volatile byte FAR0 * win, word offset,Reg16bitType val)
  92. {
  93. ((volatile word FAR0*)win)[offset>>1] = val;
  94. }
  95. /*----------------------------------------------------------------------
  96. f l W r i t e 1 6 b i t U s i n g 3 2 b i t s S i n g l e S h i f t
  97. Note : offset must be 16-bits aligned.
  98. Write 16-bit Using 16-bits operands with a single address shifted.
  99. ------------------------------------------------------------------------*/
  100. void flWrite16bitUsing32bitsSingleShift(volatile byte FAR0 * win, word offset,Reg16bitType val)
  101. {
  102. #ifdef FL_BIG_ENDIAN
  103. ((volatile dword FAR0*)win)[offset>>1] = ((dword)val)<<16;
  104. #else
  105. ((volatile dword FAR0*)win)[offset>>1] = (dword)val;
  106. #endif /* FL_BIG_ENDIAN */
  107. }
  108. /*********************************************************/
  109. /* Read 16 bits from DiskOnChip memory window */
  110. /*********************************************************/
  111. /*----------------------------------------------------------------------
  112. f l R e a d 1 6 b i t D u m m y
  113. Dummy routine - read 16-bits from memory (does nothing).
  114. ------------------------------------------------------------------------*/
  115. Reg16bitType flRead16bitDummy(volatile byte FAR0 * win,word offset)
  116. {
  117. DEBUG_PRINT(("Wrong customization - 16bit read was issued with no implementation.\r\n"));
  118. return 0;
  119. }
  120. /*----------------------------------------------------------------------
  121. f l R e a d 1 6 b i t U s i n g 1 6 b i t s N o S h i f t
  122. Note : offset must be 16-bits aligned.
  123. Read 16-bit Using 16-bits operands with no address shifted.
  124. ------------------------------------------------------------------------*/
  125. Reg16bitType flRead16bitUsing16bitsNoShift(volatile byte FAR0 * win,word offset)
  126. {
  127. return ((volatile word FAR0*)win)[offset>>1];
  128. }
  129. /*----------------------------------------------------------------------
  130. f l R e a d 1 6 b i t U s i n g 3 2 b i t s S i n g l e S h i f t
  131. Note : offset must be 16-bits aligned.
  132. Read 16-bit Using 16-bits operands with single address shifted.
  133. ------------------------------------------------------------------------*/
  134. Reg16bitType flRead16bitUsing32bitsSingleShift(volatile byte FAR0 * win,word offset)
  135. {
  136. #ifdef FL_BIG_ENDIAN
  137. return (Reg16bitType)(((volatile dword FAR0*)win)[offset>>1]<<16);
  138. #else
  139. return (Reg16bitType)((volatile dword FAR0*)win)[offset>>1];
  140. #endif /* FL_BIG_ENDIAN */
  141. }
  142. /*********************************************************/
  143. /* Write 8 bits to DiskOnChip memory window */
  144. /*********************************************************/
  145. /*----------------------------------------------------------------------
  146. f l W r i t e 8 b i t U s i n g 8 b i t s N o S h i f t
  147. Write 8-bits Using 8-bits operands with no address shifted.
  148. ------------------------------------------------------------------------*/
  149. void flWrite8bitUsing8bitsNoShift(volatile byte FAR0 * win, word offset,Reg8bitType val)
  150. {
  151. win[offset] = val;
  152. }
  153. /*----------------------------------------------------------------------
  154. f l W r i t e 8 b i t U s i n g 16 b i t s N o S h i f t
  155. Note : DiskOnChip is connected with 16-bit data bus.
  156. Note : Data is written only to lower memory addresses.
  157. Write 8-bits Using 16-bits operands with no address shifted.
  158. ------------------------------------------------------------------------*/
  159. void flWrite8bitUsing16bitsNoShift(volatile byte FAR0 * win, word offset,Reg8bitType val)
  160. {
  161. #ifdef FL_BIG_ENDIAN
  162. ((volatile word FAR0 *)win)[offset>>1] = ((word)val)<<8;
  163. #else
  164. ((volatile word FAR0 *)win)[offset>>1] = (word)val;
  165. #endif /* FL_BIG_ENDIAN */
  166. }
  167. /*----------------------------------------------------------------------
  168. f l W r i t e 8 b i t U s i n g 16 b i t s S i n g l e S h i f t
  169. Note : Data is written only to 8-LSB.
  170. Write 8-bits Using 16-bits operands with Single address shifted.
  171. ------------------------------------------------------------------------*/
  172. void flWrite8bitUsing16bitsSingleShift(volatile byte FAR0 * win, word offset,Reg8bitType val)
  173. {
  174. ((volatile word FAR0 *)win)[offset] = (word)val;
  175. }
  176. /*----------------------------------------------------------------------
  177. f l W r i t e 8 b i t U s i n g 32 b i t s S i n g l e S h i f t
  178. Note : DiskOnChip is connected with 16-bit data bus.
  179. Note : Data is written to both data bus 8-bits
  180. Write 8-bits Using 32-bits operands with single address shifted.
  181. ------------------------------------------------------------------------*/
  182. void flWrite8bitUsing32bitsSingleShift(volatile byte FAR0 * win, word offset,Reg8bitType val)
  183. {
  184. #ifdef FL_BIG_ENDIAN
  185. ((volatile dword FAR0 *)win)[offset>>1] = (dword)val*0x01010101L;
  186. #else
  187. ((volatile dword FAR0 *)win)[offset>>1] = (dword)val;
  188. #endif /* FL_BIG_ENDIAN */
  189. }
  190. /*----------------------------------------------------------------------
  191. f l W r i t e 8 b i t U s i n g 32 b i t s D o u b l e S h i f t
  192. Note : Data is written only to 8-LSB.
  193. Write 8-bits Using 32-bits operands with Double address shifted.
  194. ------------------------------------------------------------------------*/
  195. void flWrite8bitUsing32bitsDoubleShift(volatile byte FAR0 * win, word offset,Reg8bitType val)
  196. {
  197. ((volatile dword FAR0 *)win)[offset] = (dword)val;
  198. }
  199. /*********************************************************/
  200. /* Read 8 bits to DiskOnChip memory window */
  201. /*********************************************************/
  202. /*----------------------------------------------------------------------
  203. f l R e a d 8 b i t U s i n g 8 b i t s N o S h i f t
  204. Read 8-bits Using 8-bits operands with no address shifted.
  205. ------------------------------------------------------------------------*/
  206. Reg8bitType flRead8bitUsing8bitsNoShift(volatile byte FAR0 * win,word offset)
  207. {
  208. return win[offset];
  209. }
  210. /*----------------------------------------------------------------------
  211. f l R e a d 8 b i t U s i n g 16 b i t s N o S h i f t
  212. Note : DiskOnChip is connected with 16-bit data bus.
  213. Read 8-bits Using 16-bits operands with no address shifted.
  214. ------------------------------------------------------------------------*/
  215. Reg8bitType flRead8bitUsing16bitsNoShift(volatile byte FAR0 * win,word offset)
  216. {
  217. #ifdef FL_BIG_ENDIAN
  218. return (((offset & 0x1) == 0) ?
  219. #else
  220. return (( offset & 0x1 ) ?
  221. #endif /* FL_BIG_ENDIAN */
  222. (Reg8bitType)(((volatile word FAR0 *)win)[offset>>1]>>8) :
  223. (Reg8bitType) ((volatile word FAR0 *)win)[offset>>1] );
  224. }
  225. /*----------------------------------------------------------------------
  226. f l R e a d 8 b i t U s i n g 16 b i t s S i n g l e S h i f t
  227. Note : Assume data is found in 8-LSB of DiskOnChip
  228. Read 8-bits Using 16-bits operands with Single address shifted.
  229. ------------------------------------------------------------------------*/
  230. Reg8bitType flRead8bitUsing16bitsSingleShift(volatile byte FAR0 * win,word offset)
  231. {
  232. return (Reg8bitType)((volatile word FAR0 *)win)[offset];
  233. }
  234. /*----------------------------------------------------------------------
  235. f l R e a d 8 b i t U s i n g 32 b i t s S i n g l e S h i f t
  236. Note : DiskOnChip is connected with 16-bit data bus.
  237. Read 8-bits Using 16-bits operands with Single address shifted.
  238. ------------------------------------------------------------------------*/
  239. Reg8bitType flRead8bitUsing32bitsSingleShift(volatile byte FAR0 * win,word offset)
  240. {
  241. #ifdef FL_BIG_ENDIAN
  242. return (((offset & 0x1) == 0) ?
  243. #else
  244. return (( offset & 0x1 ) ?
  245. #endif /* FL_BIG_ENDIAN */
  246. (Reg8bitType)(((volatile dword FAR0 *)win)[offset>>1]>>24) :
  247. (Reg8bitType) ((volatile dword FAR0 *)win)[offset>>1] );
  248. }
  249. /*----------------------------------------------------------------------
  250. f l R e a d 8 b i t U s i n g 32 b i t s D o u b l e S h i f t
  251. Note : Assume data is found in 8-LSB of DiskOnChip
  252. Read 8-bits Using 16-bits operands with Single address shifted.
  253. ------------------------------------------------------------------------*/
  254. Reg8bitType flRead8bitUsing32bitsDoubleShift(volatile byte FAR0 * win,word offset)
  255. {
  256. return (Reg8bitType)((volatile dword FAR0 *)win)[offset];
  257. }
  258. /*********************************************************/
  259. /*********************************************************/
  260. /*** Operation on several bytes (read/write/set) ***/
  261. /*********************************************************/
  262. /*********************************************************/
  263. /*************************************************/
  264. /* 8-Bit DiskOnChip - No Shift */
  265. /*************************************************/
  266. /*----------------------------------------------------------------------
  267. f l 8 b i t D o c R e a d N o S h i f t
  268. Read 'count' bytes, from a none shifted address bus using tffscpy.
  269. ------------------------------------------------------------------------*/
  270. void fl8bitDocReadNoShift(volatile byte FAR0 * win,word offset,byte FAR1* dest,word count)
  271. {
  272. #ifdef FL_INIT_MMU_PAGES
  273. if (count == 0)
  274. return;
  275. *dest = (byte)0;
  276. *((byte FAR1*)addToFarPointer(dest, (count - 1)) ) = (byte)0;
  277. #endif /* FL_INIT_MMU_PAGES */
  278. tffscpy(dest,(void FAR0*)(win+offset),count);
  279. }
  280. /*----------------------------------------------------------------------
  281. f l 8 b i t D o c W r i t e N o S h i f t
  282. Write 'count' bytes, from a none shifted address bus using tffscpy.
  283. ------------------------------------------------------------------------*/
  284. void fl8bitDocWriteNoShift(volatile byte FAR0 * win,word offset,byte FAR1* src,word count)
  285. {
  286. tffscpy((void FAR0*)( win+offset),src,count);
  287. }
  288. /*----------------------------------------------------------------------
  289. f l 8 b i t D o c S e t N o S h i f t
  290. Set 'count' bytes, from a none shifted address bus using tffsset.
  291. ------------------------------------------------------------------------*/
  292. void fl8bitDocSetNoShift(volatile byte FAR0 * win,word offset,word count, byte val)
  293. {
  294. tffsset((void FAR0*)( win+offset),val,count);
  295. }
  296. /*************************************************/
  297. /* 8-Bit DiskOnChip - Single Shift */
  298. /*************************************************/
  299. /*----------------------------------------------------------------------
  300. f l 8 b i t D o c R e a d S i n g l e S h i f t
  301. Note : Assume data is found in 8-LSB of DiskOnChip
  302. Read 'count' bytes, from data bus's LSB lane with 1 address shifted
  303. ------------------------------------------------------------------------*/
  304. void fl8bitDocReadSingleShift(volatile byte FAR0 * win,word offset,byte FAR1* dest,word count)
  305. {
  306. volatile word FAR0 * doc = (volatile word FAR0 *) win + offset;
  307. register int i;
  308. #ifdef FL_INIT_MMU_PAGES
  309. if (count == 0)
  310. return;
  311. *dest = (byte)0;
  312. *((byte FAR1*)addToFarPointer(dest, (count - 1)) ) = (byte)0;
  313. #endif /* FL_INIT_MMU_PAGES */
  314. for(i=0;( i < count );i++)
  315. dest[i] = (Reg8bitType)doc[i];
  316. }
  317. /*----------------------------------------------------------------------
  318. f l 8 b i t D o c W r i t e S i n g l e S h i f t
  319. Note : Assume data is found in 8-LSB of DiskOnChip
  320. Write 'count' bytes, to data bus's LSB lane with 1 address shifted.
  321. ------------------------------------------------------------------------*/
  322. void fl8bitDocWriteSingleShift(volatile byte FAR0 * win,word offset,byte FAR1* src,word count)
  323. {
  324. volatile word FAR0 * doc = (volatile word FAR0 *) win + offset;
  325. register int i;
  326. for(i=0;( i < count );i++)
  327. doc[i] = (word)src[i];
  328. }
  329. /*----------------------------------------------------------------------
  330. f l 8 b i t D o c S e t S i n g l e S h i f t
  331. Note : Assume data is found in 8-LSB of DiskOnChip
  332. Set 'count' bytes, of data bus's LSB lane with 1 address shifted.
  333. ------------------------------------------------------------------------*/
  334. void fl8bitDocSetSingleShift(volatile byte FAR0 * win,word offset,word count, byte val)
  335. {
  336. volatile word FAR0 * doc = (volatile word FAR0 *) win + offset;
  337. register int i;
  338. for(i=0;( i < count );i++)
  339. doc[i] = (word)val;
  340. }
  341. /*************************************************/
  342. /* 8-Bit DiskOnChip - Double Shift */
  343. /*************************************************/
  344. /*----------------------------------------------------------------------
  345. f l 8 b i t D o c R e a d D o u b l e S h i f t
  346. Note : Assume data is found in 8-LSB of DiskOnChip
  347. Read 'count' bytes, from data bus's LSB lane with 2 address shifted.
  348. ------------------------------------------------------------------------*/
  349. void fl8bitDocReadDoubleShift(volatile byte FAR0 * win,word offset,byte FAR1* dest,word count)
  350. {
  351. volatile dword FAR0 * doc = (volatile dword FAR0 *) win + offset;
  352. register int i;
  353. #ifdef FL_INIT_MMU_PAGES
  354. if (count == 0)
  355. return;
  356. *dest = (byte)0;
  357. *((byte FAR1*)addToFarPointer(dest, (count - 1)) ) = (byte)0;
  358. #endif /* FL_INIT_MMU_PAGES */
  359. for(i=0;( i < count );i++)
  360. dest[i] = (Reg8bitType)doc[i];
  361. }
  362. /*----------------------------------------------------------------------
  363. f l 8 b i t D o c W r i t e D o u b l e S h i f t
  364. Note : Assume data is found in 8-LSB of DiskOnChip
  365. Write 'count' bytes, to data bus's LSB lane with 2 address shifted.
  366. ------------------------------------------------------------------------*/
  367. void fl8bitDocWriteDoubleShift(volatile byte FAR0 * win,word offset,byte FAR1* src,word count)
  368. {
  369. volatile dword FAR0 * doc = (volatile dword FAR0 *) win + offset;
  370. register int i;
  371. for(i=0;( i < count );i++)
  372. doc[i] = (dword)src[i];
  373. }
  374. /*----------------------------------------------------------------------
  375. f l 8 b i t D o c S e t D o u b l e S h i f t
  376. Note : Assume data is found in 8-LSB of DiskOnChip
  377. Set 'count' bytes, of data bus's LSB lane with 2 address shifted.
  378. ------------------------------------------------------------------------*/
  379. void fl8bitDocSetDoubleShift(volatile byte FAR0 * win,word offset,word count, byte val)
  380. {
  381. volatile dword FAR0 * doc = (volatile dword FAR0 *) win+offset;
  382. register int i;
  383. for(i=0;( i < count );i++)
  384. doc[i] = (dword)val;
  385. }
  386. /*************************************************/
  387. /* 16-Bit DiskOnChip - No Shift */
  388. /*************************************************/
  389. /*----------------------------------------------------------------------
  390. f l 1 6 b i t D o c R e a d N o S h i f t
  391. Read 'count' bytes from M+ DiskOnChip with none shifted address bus.
  392. ------------------------------------------------------------------------*/
  393. void fl16bitDocReadNoShift (volatile byte FAR0 * win, word offset, byte FAR1 * dest, word count )
  394. {
  395. volatile word FAR0 * swin = (volatile word FAR0 *)( win + offset);
  396. register int i;
  397. register word tmp;
  398. #ifdef FL_INIT_MMU_PAGES
  399. if (count == 0)
  400. return;
  401. *dest = (byte)0;
  402. *((byte FAR1*)addToFarPointer(dest, (count - 1)) ) = (byte)0;
  403. #endif /* FL_INIT_MMU_PAGES */
  404. if( pointerToPhysical(dest) & 0x1 )
  405. {
  406. /* rare case: unaligned target buffer */
  407. for (i = 0; i < (int)count; )
  408. {
  409. tmp = *swin;
  410. #ifdef FL_BIG_ENDIAN
  411. dest[i++] = (byte)(tmp>>8);
  412. dest[i++] = (byte)tmp;
  413. #else
  414. dest[i++] = (byte)tmp;
  415. dest[i++] = (byte)(tmp>>8);
  416. #endif /* FL_BIG_ENDIAN */
  417. }
  418. }
  419. else
  420. { /* mainstream case */
  421. #ifdef USE_TFFS_COPY
  422. tffscpy( dest, (void FAR0 *)( win + offset), count );
  423. #else
  424. #ifdef ENVIRONMENT_VARS
  425. if (flUse8Bit == 0)
  426. {
  427. flcpy( dest, (void FAR0 *)( win + offset), count );
  428. }
  429. else
  430. #endif /* ENVIRONMENT_VARS */
  431. { /* read in short words */
  432. for (i = 0, count = count >> 1; i < (int)count; i++)
  433. ((word FAR1 *)dest)[i] = swin[i];
  434. }
  435. #endif /* USE_TFFS_COPY */
  436. }
  437. }
  438. /*----------------------------------------------------------------------
  439. f l 1 6 b i t D o c W r i t e N o S h i f t
  440. Write 'count' bytes to M+ DiskOnChip with none shifted address bus.
  441. ------------------------------------------------------------------------*/
  442. void fl16bitDocWriteNoShift ( volatile byte FAR0 * win , word offset ,
  443. byte FAR1 * src, word count )
  444. {
  445. volatile word FAR0 * swin = (volatile word FAR0 *)( win + offset);
  446. register int i;
  447. register word tmp;
  448. if( pointerToPhysical(src) & 0x1 ) /* rare case: unaligned source buffer */
  449. {
  450. for (i = 0; i < (int)count; i+=2)
  451. {
  452. /* tmp variable is just a precation from compiler optimizations */
  453. #ifdef FL_BIG_ENDAIN
  454. tmp = ((word)src[i]<<8) + (word)src[i+1];
  455. #else
  456. tmp = (word)src[i] + ((word)src[i+1]<<8);
  457. #endif /* FL_BIG_ENDAIN */
  458. *swin = tmp;
  459. }
  460. }
  461. else /* mainstream case */
  462. {
  463. #ifdef USE_TFFS_COPY
  464. tffscpy( (void FAR0 *)(win + offset), src, count );
  465. #else
  466. #ifdef ENVIRONMENT_VARS
  467. if (flUse8Bit == 0)
  468. {
  469. flcpy( (void FAR0 *)(win + offset), src, count );
  470. }
  471. else
  472. #endif /* ENVIRONMENT_VARS */
  473. { /* write in short words */
  474. for (i = 0, count = count >> 1; i < (int)count; i++)
  475. *swin = ((word FAR1 *)src)[i];
  476. }
  477. #endif /* USE_TFFS_COPY */
  478. }
  479. }
  480. /*----------------------------------------------------------------------
  481. f l 1 6 b i t D o c S e t N o S h i f t
  482. Set 'count' bytes of M+ DiskOnChip with none shifted address bus
  483. ------------------------------------------------------------------------*/
  484. void fl16bitDocSetNoShift ( volatile byte FAR0 * win , word offset ,
  485. word count , byte val)
  486. {
  487. volatile word FAR0 * swin = (volatile word FAR0 *)( win + offset);
  488. register int i;
  489. word tmpVal = (word)val * 0x0101;
  490. #ifdef USE_TFFS_COPY
  491. tffsset( (void FAR0 *)(win + offset), val, count );
  492. #else
  493. #ifdef ENVIRONMENT_VARS
  494. if (flUse8Bit == 0)
  495. {
  496. flset( (void FAR0 *)(win + offset), val, count );
  497. }
  498. else
  499. #endif /* ENVIRONMENT_VARS */
  500. { /* write in short words */
  501. for (i = 0; i < (int)count; i+=2)
  502. *swin = tmpVal;
  503. }
  504. #endif /* USE_TFFS_COPY */
  505. }
  506. /*************************************************************/
  507. /* 16-Bit DiskOnChip - No Shift - Only 8 bits are valid */
  508. /*************************************************************/
  509. /*----------------------------------------------------------------------
  510. f l 1 6 b i t D o c R e a d N o S h i f t I g n o r e H i g h e r 8 B i t s
  511. Note : offset must be 16-bits aligned.
  512. Read 'count' bytes from M+ DiskOnChip connected with all 16 data bits, but
  513. in interleave-1 mode , therefore only one of the 8 bits contains actual data.
  514. The DiskOnChip is connected without an address shift.
  515. ------------------------------------------------------------------------*/
  516. void fl16bitDocReadNoShiftIgnoreHigher8bits(volatile byte FAR0 * win, word offset, byte FAR1 * dest, word count )
  517. {
  518. volatile word FAR0 * swin = (volatile word FAR0 *)( win + offset);
  519. register int i;
  520. #ifdef FL_INIT_MMU_PAGES
  521. if (count == 0)
  522. return;
  523. *dest = (byte)0;
  524. *((byte FAR1*)addToFarPointer(dest, (count - 1)) ) = (byte)0;
  525. #endif /* FL_INIT_MMU_PAGES */
  526. for (i = 0; i < (int)count; i++)
  527. {
  528. #ifdef FL_BIG_ENDIAN
  529. dest[i] = (byte)(swin[i]>>8);
  530. #else
  531. dest[i] = (byte)swin[i];
  532. #endif /* FL_BIG_ENDIAN */
  533. }
  534. }
  535. /*----------------------------------------------------------------------
  536. f l 1 6 D o c W r i t e N o S h i f t I g n o r e H i g h e r 8 b i t s
  537. Note : offset must be 16-bits aligned.
  538. Write 'count' bytes to M+ DiskOnChip connected with all 16 data bits, but
  539. in interleave-1 mode , therefore only one of the 8bits contains actual data.
  540. The DiskOnChip is connected without an address shift.
  541. ------------------------------------------------------------------------*/
  542. void fl16bitDocWriteNoShiftIgnoreHigher8bits ( volatile byte FAR0 * win , word offset ,
  543. byte FAR1 * src, word count )
  544. {
  545. volatile word FAR0 * swin = (volatile word FAR0 *)( win + offset);
  546. register int i;
  547. for (i = 0; i < (int)count; i++)
  548. {
  549. #ifdef FL_BIG_ENDIAN
  550. *swin = ((word)src[i])<<8;
  551. #else
  552. *swin = (word)src[i];
  553. #endif /* FL_BIG_ENDIAN */
  554. }
  555. }
  556. /*----------------------------------------------------------------------
  557. f l 1 6 D o c S e t N o S h i f t I g n o r e H i g h e r 8 b i t s
  558. Note : offset must be 16-bits aligned.
  559. Set 'count' bytes to M+ DiskOnChip connected with all 16 data bits, but
  560. in interleave-1 mode , therefore only one of the 8bits contains actual data.
  561. The DiskOnChip is connected without an address shift.
  562. ------------------------------------------------------------------------*/
  563. void fl16bitDocSetNoShiftIgnoreHigher8bits ( volatile byte FAR0 * win , word offset ,
  564. word count , byte val)
  565. {
  566. volatile word FAR0 * swin = (volatile word FAR0 *)( win + offset);
  567. register int i;
  568. word tmpVal = val * 0x0101;
  569. for (i = 0; i < (int)count; i++)
  570. *swin = tmpVal;
  571. }
  572. /****************************************/
  573. /* 16-Bit DiskOnChip - Single Shift */
  574. /****************************************/
  575. /*----------------------------------------------------------------------
  576. f l 1 6 b i t D o c R e a d S i n g l e S h i f t
  577. Read 'count' bytes from M+ DiskOnChip with none shifted address bus.
  578. ------------------------------------------------------------------------*/
  579. void fl16bitDocReadSingleShift (volatile byte FAR0 * win, word offset, byte FAR1 * dest, word count )
  580. {
  581. volatile dword FAR0 * swin = (volatile dword FAR0 *)win + (offset>>1);
  582. register int i;
  583. register dword tmp;
  584. #ifdef FL_INIT_MMU_PAGES
  585. if (count == 0)
  586. return;
  587. *dest = (byte)0;
  588. *((byte FAR1*)addToFarPointer(dest, (count - 1)) ) = (byte)0;
  589. #endif /* FL_INIT_MMU_PAGES */
  590. if( pointerToPhysical(dest) & 0x1 )
  591. {
  592. /* rare case: unaligned target buffer */
  593. for (i = 0; i < (int)count; )
  594. {
  595. tmp = *swin;
  596. #ifdef FL_BIG_ENDAIN
  597. dest[i++] = (byte)(tmp>>24);
  598. dest[i++] = (byte)(tmp>>16);
  599. #else
  600. dest[i++] = (byte)tmp;
  601. dest[i++] = (byte)(tmp>>8);
  602. #endif /* FL_BIG_ENDAIN */
  603. }
  604. }
  605. else
  606. { /* mainstream case */
  607. for (i = 0, count = count >> 1; i < (int)count; i++)
  608. {
  609. #ifdef FL_BIG_ENDAIN
  610. ((word FAR1 *)dest)[i] = (word)(swin[i]>>16);
  611. #else
  612. ((word FAR1 *)dest)[i] = (word)swin[i];
  613. #endif /* FL_BIG_ENDAIN */
  614. }
  615. }
  616. }
  617. /*----------------------------------------------------------------------
  618. f l 1 6 b i t D o c W r i t e S i n g l e S h i f t
  619. Write 'count' bytes to M+ DiskOnChip with none shifted address bus.
  620. ------------------------------------------------------------------------*/
  621. void fl16bitDocWriteSingleShift ( volatile byte FAR0 * win , word offset ,
  622. byte FAR1 * src, word count )
  623. {
  624. volatile dword FAR0 * swin = (volatile dword FAR0 *)win + (offset>>1);
  625. register int i;
  626. register dword tmp;
  627. if( pointerToPhysical(src) & 0x1 ) /* rare case: unaligned source buffer */
  628. {
  629. for (i = 0; i < (int)count; i+=2)
  630. {
  631. #ifdef FL_BIG_ENDAIN
  632. tmp = (((dword)src[i])<<24) + (((dword)src[i+1])<<16);
  633. #else
  634. tmp = (dword)src[i] + (((dword)src[i+1])<<8);
  635. #endif /* FL_BIG_ENDAIN */
  636. *swin = tmp;
  637. }
  638. }
  639. else /* mainstream case */
  640. {
  641. for (i = 0, count = count >> 1; i < (int)count; i++)
  642. #ifdef FL_BIG_ENDIAN
  643. *swin = ((dword)((word FAR1 *)src)[i])<<16;
  644. #else
  645. *swin = (dword)((word FAR1 *)src)[i];
  646. #endif /* FL_BIG_ENDIAN */
  647. }
  648. }
  649. /*----------------------------------------------------------------------
  650. f l 1 6 b i t D o c S e t S i n g l e S h i f t
  651. Set 'count' bytes of M+ DiskOnChip with none shifted address bus
  652. ------------------------------------------------------------------------*/
  653. void fl16bitDocSetSingleShift ( volatile byte FAR0 * win , word offset ,
  654. word count , byte val)
  655. {
  656. volatile dword FAR0 * swin = (volatile dword FAR0 *)win + (offset>>1);
  657. register int i;
  658. register dword tmpVal = (dword)val * 0x01010101L;
  659. for (i = 0; i < (int)count; i+=2)
  660. *swin = tmpVal;
  661. }
  662. /**************************************************************/
  663. /* 16-Bit DiskOnChip - Single Shift - Only 8 bits are valid */
  664. /**************************************************************/
  665. /*----------------------------------------------------------------------
  666. f l 1 6 b i t D o c R e a d S i n g l e S h i f t I g n o r e H i g h e r 8 B i t s
  667. Note : offset must be 16-bits aligned.
  668. Read 'count' bytes from M+ DiskOnChip connected with all 16 data bits, but
  669. in interleave-1 mode , therefore only one of the 8 bits contains actual data.
  670. The DiskOnChip is connected without an address shift.
  671. ------------------------------------------------------------------------*/
  672. void fl16bitDocReadSingleShiftIgnoreHigher8bits(volatile byte FAR0 * win, word offset, byte FAR1 * dest, word count )
  673. {
  674. volatile dword FAR0 * swin = (volatile dword FAR0 *)win + (offset>>1);
  675. register int i;
  676. #ifdef FL_INIT_MMU_PAGES
  677. if (count == 0)
  678. return;
  679. *dest = (byte)0;
  680. *((byte FAR1*)addToFarPointer(dest, (count - 1)) ) = (byte)0;
  681. #endif /* FL_INIT_MMU_PAGES */
  682. for (i = 0; i < (int)count; i++)
  683. {
  684. #ifdef FL_BIG_ENDAIN
  685. dest[i] = (byte)(swin[i]>>24);
  686. #else
  687. dest[i] = (byte)swin[i];
  688. #endif /* FL_BIG_ENDAIN */
  689. }
  690. }
  691. /*----------------------------------------------------------------------
  692. f l 1 6 D o c W r i t e S i n g l e S h i f t I g n o r e H i g h e r 8 b i t s
  693. Note : offset must be 16-bits aligned.
  694. Write 'count' bytes to M+ DiskOnChip connected with all 16 data bits, but
  695. in interleave-1 mode , therefore only one of the 8bits contains actual data.
  696. The DiskOnChip is connected without an address shift.
  697. ------------------------------------------------------------------------*/
  698. void fl16bitDocWriteSingleShiftIgnoreHigher8bits ( volatile byte FAR0 * win , word offset ,
  699. byte FAR1 * src, word count )
  700. {
  701. volatile dword FAR0 * swin = (volatile dword FAR0 *)win + (offset>>1);
  702. register int i;
  703. for (i = 0; i < (int)count; i++)
  704. {
  705. #ifdef FL_BIG_ENDAIN
  706. *swin = ((dword)src[i]<<24);
  707. #else
  708. *swin = (dword)src[i];
  709. #endif /* FL_BIG_ENDAIN */
  710. }
  711. }
  712. /*----------------------------------------------------------------------
  713. f l 1 6 D o c S e t S i n g l e S h i f t I g n o r e H i g h e r 8 b i t s
  714. Note : offset must be 16-bits aligned.
  715. Set 'count' bytes to M+ DiskOnChip connected with all 16 data bits, but
  716. in interleave-1 mode , therefore only one of the 8bits contains actual data.
  717. The DiskOnChip is connected without an address shift.
  718. ------------------------------------------------------------------------*/
  719. void fl16bitDocSetSingleShiftIgnoreHigher8bits ( volatile byte FAR0 * win , word offset ,
  720. word count , byte val)
  721. {
  722. volatile dword FAR0 * swin = (volatile dword FAR0 *)win + (offset>>1);
  723. register int i;
  724. dword tmpVal = (dword)val * 0x01010101L;
  725. for (i = 0; i < (int)count; i++)
  726. *swin = tmpVal;
  727. }
  728. /**********************************************************/
  729. /* Set proper access type routines into the proper record */
  730. /**********************************************************/
  731. /*----------------------------------------------------------------------*/
  732. /* s e t B u s T y p e O f F l a s h */
  733. /* */
  734. /* Set DiskOnChip socket / flash memory access routine. */
  735. /* This routine must be called by the MTD prior to any access to the */
  736. /* DiskOnChip */
  737. /* */
  738. /* Parameters: */
  739. /* flflash : Pointer to sockets flash record. */
  740. /* access : Type of memory access routines to install */
  741. /* */
  742. /* Note: The possible type of memory access routine are comprised of: */
  743. /* */
  744. /* Address shift: */
  745. /* FL_NO_ADDR_SHIFT - No address shift */
  746. /* FL_SINGLE_ADDR_SHIFT - Single address shift */
  747. /* FL_DOUBLE_ADDR_SHIFT - Double address shift */
  748. /* */
  749. /* Platform bus capabilities (access width): */
  750. /* FL_BUS_HAS_8BIT_ACCESS - Bus can access 8-bit */
  751. /* FL_BUS_HAS_16BIT_ACCESS - Bus can access 16-bit */
  752. /* FL_BUS_HAS_32BIT_ACCESS - Bus can access 32-bit */
  753. /* */
  754. /* Number of data bits connected to the DiskOnChip (if_cfg): */
  755. /* FL_8BIT_DOC_ACCESS - DiskOnChip has 8 data bits */
  756. /* FL_16BIT_DOC_ACCESS - DiskOnChip has 16 data bits */
  757. /* */
  758. /* Flash data bits that can be accessed in a bus cycle (interleave): */
  759. /* FL_8BIT_FLASH_ACCESS - 8 bits of flash per cycle */
  760. /* FL_16BIT_FLASH_ACCESS - 16 bits of flash per cycle */
  761. /* */
  762. /* Ignore all of the above and use user defined access routines: */
  763. /* FL_ACCESS_USER_DEFINED - Do not install any routine since */
  764. /* user already installed custome made */
  765. /* routines */
  766. /* */
  767. /* Returns: */
  768. /* FLStatus : 0 on success, otherwise failed */
  769. /*----------------------------------------------------------------------*/
  770. FLStatus setBusTypeOfFlash(FLFlash * flash,dword access)
  771. {
  772. /* sanity checks here if needed */
  773. if(flash==NULL)
  774. {
  775. DEBUG_PRINT(("Flash record passed to setBusTypeOfFlash is NULL.\r\n"));
  776. return flBadParameter;
  777. }
  778. /* check if user already defined the memory access routines */
  779. if ((access & FL_ACCESS_USER_DEFINED) != 0)
  780. return flOK;
  781. /************************************/
  782. /* install requested access methods */
  783. /************************************/
  784. switch(access & FL_XX_ADDR_SHIFT_MASK)
  785. {
  786. case FL_NO_ADDR_SHIFT:
  787. flash->memWindowSize = &flDocMemWinSizeNoShift;
  788. switch(access & FL_XX_DATA_BITS_MASK)
  789. {
  790. case FL_8BIT_DOC_ACCESS: /* if_cfg set to 8-bits */
  791. /* Make sure bus supports 8 bit access */
  792. if((access & FL_BUS_HAS_8BIT_ACCESS) == 0)
  793. {
  794. DEBUG_PRINT(("ERROR: TrueFFS requires 8-bit access to DiskOnChip memory window\r\n"));
  795. DEBUG_PRINT((" for 8-bit DiskOnChip connected with no address shift.\r\n"));
  796. return flBadParameter;
  797. }
  798. flash->memWrite8bit = &flWrite8bitUsing8bitsNoShift;
  799. flash->memRead8bit = &flRead8bitUsing8bitsNoShift;
  800. flash->memRead16bit = &flRead16bitDummy;
  801. flash->memWrite16bit = &flWrite16bitDummy;
  802. flash->memRead = &fl8bitDocReadNoShift;
  803. flash->memWrite = &fl8bitDocWriteNoShift;
  804. flash->memSet = &fl8bitDocSetNoShift;
  805. break;
  806. case FL_16BIT_DOC_ACCESS: /* if_cfg set to 16-bits (Plus family) */
  807. /* Make sure bus supports 16 bit access */
  808. if((access & FL_BUS_HAS_16BIT_ACCESS) == 0)
  809. {
  810. DEBUG_PRINT(("ERROR: TrueFFS requires 16-bit access to DiskOnChip memory window\r\n"));
  811. DEBUG_PRINT((" for 16-bit DiskOnChip connected with no address shift.\r\n"));
  812. return flBadParameter;
  813. }
  814. flash->memWrite8bit = &flWrite8bitUsing16bitsNoShift;
  815. flash->memRead8bit = &flRead8bitUsing16bitsNoShift;
  816. flash->memRead16bit = &flRead16bitUsing16bitsNoShift;
  817. flash->memWrite16bit = &flWrite16bitUsing16bitsNoShift;
  818. switch(access & FL_XX_FLASH_ACCESS_MASK) /* Interleave */
  819. {
  820. case FL_8BIT_FLASH_ACCESS: /* Interleave - 1 */
  821. flash->memRead = &fl16bitDocReadNoShiftIgnoreHigher8bits;
  822. flash->memWrite = &fl16bitDocWriteNoShiftIgnoreHigher8bits;
  823. flash->memSet = &fl16bitDocSetNoShiftIgnoreHigher8bits;
  824. break;
  825. case FL_16BIT_FLASH_ACCESS: /* Interleave - 2 */
  826. flash->memRead = &fl16bitDocReadNoShift;
  827. flash->memWrite = &fl16bitDocWriteNoShift;
  828. flash->memSet = &fl16bitDocSetNoShift;
  829. break;
  830. default:
  831. DEBUG_PRINT(("TrueFFS does not support this flash access type (setBusTypeOfFlash).\r\n"));
  832. return flBadParameter;
  833. }
  834. break;
  835. default:
  836. DEBUG_PRINT(("TrueFFS does not support this number of DiskOnChip data bits (setBusTypeOfFlash).\r\n"));
  837. return flBadParameter;
  838. }
  839. break;
  840. case FL_SINGLE_ADDR_SHIFT:
  841. /* Install memory window size routine */
  842. flash->memWindowSize = &flDocMemWinSizeSingleShift;
  843. switch(access & FL_XX_DATA_BITS_MASK)
  844. {
  845. case FL_8BIT_DOC_ACCESS: /* if_cfg set to 8bits (None plus family)*/
  846. /* Make sure bus supports 16 bit access */
  847. if((access & FL_BUS_HAS_16BIT_ACCESS) == 0)
  848. {
  849. DEBUG_PRINT(("ERROR: TrueFFS requires 16-bit access to DiskOnChip memory window\r\n"));
  850. DEBUG_PRINT((" for 8-bit DiskOnChip connected with a single address shift.\r\n"));
  851. return flBadParameter;
  852. }
  853. flash->memWrite8bit = &flWrite8bitUsing16bitsSingleShift;
  854. flash->memRead8bit = &flRead8bitUsing16bitsSingleShift;
  855. flash->memRead16bit = &flRead16bitDummy;
  856. flash->memWrite16bit = &flWrite16bitDummy;
  857. flash->memRead = &fl8bitDocReadSingleShift;
  858. flash->memWrite = &fl8bitDocWriteSingleShift;
  859. flash->memSet = &fl8bitDocSetSingleShift;
  860. break;
  861. case FL_16BIT_DOC_ACCESS: /* if_cfg set to 8bits (Plus family) */
  862. /* Make sure bus supports 32 bit access */
  863. if((access & FL_BUS_HAS_32BIT_ACCESS) == 0)
  864. {
  865. DEBUG_PRINT(("ERROR: TrueFFS requires 32-bit access to DiskOnChip memory window\r\n"));
  866. DEBUG_PRINT((" for 16-bit DiskOnChip connected with a single address shift.\r\n"));
  867. return flBadParameter;
  868. }
  869. flash->memWrite8bit = &flWrite8bitUsing32bitsSingleShift;
  870. flash->memRead8bit = &flRead8bitUsing32bitsSingleShift;
  871. flash->memRead16bit = &flRead16bitUsing32bitsSingleShift;
  872. flash->memWrite16bit = &flWrite16bitUsing32bitsSingleShift;
  873. switch(access & FL_XX_FLASH_ACCESS_MASK) /* Interleave */
  874. {
  875. case FL_8BIT_FLASH_ACCESS: /* Interleave - 1 */
  876. flash->memRead = &fl16bitDocReadSingleShiftIgnoreHigher8bits;
  877. flash->memWrite = &fl16bitDocWriteSingleShiftIgnoreHigher8bits;
  878. flash->memSet = &fl16bitDocSetSingleShiftIgnoreHigher8bits;
  879. break;
  880. case FL_16BIT_FLASH_ACCESS: /* Interleave - 2 */
  881. flash->memRead = &fl16bitDocReadSingleShift;
  882. flash->memWrite = &fl16bitDocWriteSingleShift;
  883. flash->memSet = &fl16bitDocSetSingleShift;
  884. break;
  885. default:
  886. DEBUG_PRINT(("TrueFFS does not support this flash access type (setBusTypeOfFlash).\r\n"));
  887. return flBadParameter;
  888. }
  889. break;
  890. default:
  891. DEBUG_PRINT(("TrueFFS does not support this number of DiskOnChip data bits (setBusTypeOfFlash).\r\n"));
  892. return flBadParameter;
  893. }
  894. break;
  895. case FL_DOUBLE_ADDR_SHIFT:
  896. /* Install memory window size routine */
  897. flash->memWindowSize = &flDocMemWinSizeDoubleShift;
  898. switch(access & FL_XX_DATA_BITS_MASK)
  899. {
  900. case FL_8BIT_DOC_ACCESS: /* if_cfg set to 8bits or none plus family */
  901. /* Make sure bus supports 32 bit access */
  902. if((access & FL_BUS_HAS_32BIT_ACCESS) == 0)
  903. {
  904. DEBUG_PRINT(("ERROR: TrueFFS requires 32-bit access to DiskOnChip memory window\r\n"));
  905. DEBUG_PRINT((" for 8-bit DiskOnChip connected with a double address shift.\r\n"));
  906. return flBadParameter;
  907. }
  908. flash->memWrite8bit = &flWrite8bitUsing32bitsDoubleShift;
  909. flash->memRead8bit = &flRead8bitUsing32bitsDoubleShift;
  910. flash->memRead16bit = &flRead16bitDummy;
  911. flash->memWrite16bit = &flWrite16bitDummy;
  912. flash->memRead = &fl8bitDocReadDoubleShift;
  913. flash->memWrite = &fl8bitDocWriteDoubleShift;
  914. flash->memSet = &fl8bitDocSetDoubleShift;
  915. break;
  916. default:
  917. DEBUG_PRINT(("TrueFFS does not support this number of DiskOnChip data bits\r\n"));
  918. DEBUG_PRINT(("when connected with a double address shift (setBusTypeOfFlash).\r\n"));
  919. return flBadParameter;
  920. }
  921. break;
  922. default:
  923. DEBUG_PRINT(("TrueFFS does not support this kind of address shifting (setBusTypeOfFlash).\r\n"));
  924. return flBadParameter;
  925. }
  926. /* Store access type in flash record */
  927. flash->busAccessType = access;
  928. return flOK;
  929. }
  930. #endif /* FL_NO_USE_FUNC */