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.

199 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1991-1998 Microsoft Corporation
  3. Module Name:
  4. mtd.c
  5. Abstract:
  6. This module supplies the structure for simple "mtd" functionality
  7. for memory card devices.
  8. Note that to keep the driver simple, and because of the limited
  9. number of memory technologies, the code supplied here does not
  10. implement true mtd capability where an independent device driver
  11. is loaded. Instead, the driver allows a device to name its technology,
  12. but the choices are limited to what is directly implemented here.
  13. Alternatively, this could be extended to add a p-code style interpreter
  14. to allow for greater flexibility, but that's not in here yet.
  15. Author:
  16. Neil Sandlin (neilsa) 26-Apr-99
  17. Environment:
  18. Kernel mode only.
  19. --*/
  20. #include "pch.h"
  21. //
  22. // Internal References
  23. //
  24. VOID
  25. MtdStandardRead(
  26. IN PVOID TargetBuffer,
  27. IN CONST PVOID DeviceBuffer,
  28. IN ULONG Length
  29. );
  30. VOID
  31. MtdSramWrite(
  32. IN CONST PVOID SourceBuffer,
  33. IN PVOID DeviceBuffer,
  34. IN ULONG Length
  35. );
  36. VOID
  37. MtdUndefinedRead(
  38. IN PVOID TargetBuffer,
  39. IN CONST PVOID DeviceBuffer,
  40. IN ULONG Length
  41. );
  42. VOID
  43. MtdUndefinedWrite(
  44. IN CONST PVOID SourceBuffer,
  45. IN PVOID DeviceBuffer,
  46. IN ULONG Length
  47. );
  48. #ifdef ALLOC_PRAGMA
  49. #pragma alloc_text(PAGE,MemCardInitializeMtd)
  50. #pragma alloc_text(PAGE,MtdStandardRead)
  51. #pragma alloc_text(PAGE,MtdSramWrite)
  52. #endif
  53. typedef struct _MTD_ENTRY {
  54. PCWSTR TechnologyName;
  55. VOID (*MtdReadProc)(
  56. IN PVOID TargetBuffer,
  57. IN CONST PVOID DeviceBuffer,
  58. IN ULONG Length
  59. );
  60. VOID (*MtdWriteProc)(
  61. IN PVOID TargetBuffer,
  62. IN CONST PVOID DeviceBuffer,
  63. IN ULONG Length
  64. );
  65. } MTD_ENTRY, *PMTD_ENTRY;
  66. MTD_ENTRY MtdTable[] = {
  67. L"UNDEFINED", MtdUndefinedRead, MtdUndefinedWrite,
  68. L"SRAM", MtdStandardRead, MtdSramWrite,
  69. NULL, NULL, NULL
  70. };
  71. NTSTATUS
  72. MemCardInitializeMtd(
  73. IN PMEMCARD_EXTENSION memcardExtension,
  74. IN PUNICODE_STRING TechnologyName
  75. )
  76. /*++
  77. Routine Description:
  78. Arguments:
  79. device extension for the card
  80. Return Value:
  81. --*/
  82. {
  83. ULONG i = 0;
  84. memcardExtension->TechnologyIndex = 0;
  85. while(MtdTable[i].TechnologyName) {
  86. UNICODE_STRING tableName;
  87. RtlInitUnicodeString(&tableName, MtdTable[i].TechnologyName);
  88. if (!RtlCompareUnicodeString(TechnologyName, &tableName, TRUE)) {
  89. memcardExtension->TechnologyIndex = i;
  90. return STATUS_SUCCESS;
  91. }
  92. i++;
  93. }
  94. return STATUS_INVALID_PARAMETER;
  95. }
  96. VOID
  97. MemCardMtdRead(
  98. IN PMEMCARD_EXTENSION memcardExtension,
  99. IN PVOID TargetBuffer,
  100. IN CONST PVOID DeviceBuffer,
  101. IN ULONG Length
  102. )
  103. {
  104. (*MtdTable[memcardExtension->TechnologyIndex].MtdReadProc)(TargetBuffer, DeviceBuffer, Length);
  105. }
  106. VOID
  107. MemCardMtdWrite(
  108. IN PMEMCARD_EXTENSION memcardExtension,
  109. IN CONST PVOID SourceBuffer,
  110. IN PVOID DeviceBuffer,
  111. IN ULONG Length
  112. )
  113. {
  114. (*MtdTable[memcardExtension->TechnologyIndex].MtdWriteProc)(SourceBuffer, DeviceBuffer, Length);
  115. }
  116. VOID
  117. MtdUndefinedRead(
  118. IN PVOID TargetBuffer,
  119. IN CONST PVOID DeviceBuffer,
  120. IN ULONG Length
  121. )
  122. {
  123. }
  124. VOID
  125. MtdUndefinedWrite(
  126. IN CONST PVOID SourceBuffer,
  127. IN PVOID DeviceBuffer,
  128. IN ULONG Length
  129. )
  130. {
  131. }
  132. VOID
  133. MtdStandardRead(
  134. IN PVOID TargetBuffer,
  135. IN CONST PVOID DeviceBuffer,
  136. IN ULONG Length
  137. )
  138. {
  139. RtlCopyMemory(TargetBuffer, DeviceBuffer, Length);
  140. }
  141. VOID
  142. MtdSramWrite(
  143. IN CONST PVOID SourceBuffer,
  144. IN PVOID DeviceBuffer,
  145. IN ULONG Length
  146. )
  147. {
  148. RtlCopyMemory(DeviceBuffer, SourceBuffer, Length);
  149. }