Windows NT 4.0 source code leak
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.

636 lines
16 KiB

5 years ago
  1. /*++
  2. Copyright (c) 1993, 1994 Digital Equipment Corporation
  3. Module Name:
  4. addrsup.c
  5. Abstract:
  6. This module contains the platform dependent code to create bus addreses
  7. and QVAs for the EB66 system.
  8. Author:
  9. Joe Notarangelo 22-Oct-1993
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. Eric Rehm (Digital) 03-Jan-1994
  14. Added PCIBus(0) and dense space support to all routines.
  15. --*/
  16. #include "halp.h"
  17. #include "eisa.h"
  18. #include "eb66def.h"
  19. typedef PVOID QUASI_VIRTUAL_ADDRESS;
  20. #ifndef AXP_FIRMWARE
  21. QUASI_VIRTUAL_ADDRESS
  22. HalCreateQva(
  23. IN PHYSICAL_ADDRESS PA,
  24. IN PVOID VA
  25. );
  26. #endif
  27. #ifdef AXP_FIRMWARE
  28. //
  29. // Place the appropriate functions in the discardable text section.
  30. //
  31. //
  32. // Local function prototypes
  33. //
  34. PVOID
  35. HalCreateQva(
  36. IN PHYSICAL_ADDRESS PA,
  37. IN PVOID VA
  38. );
  39. PVOID
  40. HalDereferenceQva(
  41. PVOID Qva,
  42. INTERFACE_TYPE InterfaceType,
  43. ULONG BusNumber
  44. );
  45. #pragma alloc_text(DISTEXT, HalpTranslateSystemBusAddress)
  46. #pragma alloc_text(DISTEXT, HalCreateQva)
  47. #pragma alloc_text(DISTEXT, HalDereferenceQva)
  48. #endif
  49. BOOLEAN
  50. HalpTranslateSystemBusAddress(
  51. IN PBUS_HANDLER BusHandler,
  52. IN PBUS_HANDLER RootHandler,
  53. IN PHYSICAL_ADDRESS BusAddress,
  54. IN OUT PULONG AddressSpace,
  55. OUT PPHYSICAL_ADDRESS TranslatedAddress
  56. )
  57. /*++
  58. Routine Description:
  59. This function returns the system physical address for a specified I/O bus
  60. address. The return value is suitable for use in a subsequent call to
  61. MmMapIoSpace.
  62. Arguments:
  63. BusHandler - Registered BUSHANDLER for the target configuration space
  64. Supplies the bus handler (bus no, interface type).
  65. RootHandler - Registered BUSHANDLER for the orginating
  66. HalTranslateBusAddress request.
  67. BusAddress - Supplies the bus relative address.
  68. AddressSpace - Supplies the address space number for the device: 0 for
  69. memory and 1 for I/O space. If the desired access mode is user mode,
  70. then bit 1 must be TRUE.
  71. TranslatedAddress - Supplies a pointer to return the translated address
  72. Notes:
  73. This is a variation of what began in the MIPS code. The intel code often
  74. assumes that if an address is in I/O space, the bottom 32 bits of the
  75. physical address can be used "like" a virtual address, and are returned
  76. to the user. This doesn't work on MIPs machines where physical
  77. addresses can be larger than 32 bits.
  78. Since we are using superpage addresses for I/O on Alpha, we can do
  79. almost what is done on intel. If AddressSpace is equal to 0 or 1, then
  80. we assume the user is doing kernel I/O and we call
  81. HalCreateQva to build a Quasi Virtual Address and return
  82. that to the caller. We then set AddressSpace to a 1, so that the caller
  83. will not call MmMapIoSpace. The Caller will use the low 32 bits of the
  84. physical address we return as the VA. (Which we built a QVA in).
  85. If the caller wants to access EISA I/O or Memory through user mode, then
  86. the caller must set bit 1 in AddressSpace to a 1 (AddressSpace=2 or 3,
  87. depending on whether EISA I/O or Memory), then the caller is returned the
  88. 34 bit Physical address. The caller will then call MmMapIoSpace, or
  89. ZwMapViewOfSection which in turn calls HalCreateQva to build a QVA out
  90. of a VA mapped through the page tables.
  91. **** Note ****
  92. The QVA in user mode can only be used via the user-mode access macros.
  93. Return Value:
  94. A return value of TRUE indicates that a system physical address
  95. corresponding to the supplied bus relative address and bus address
  96. number has been returned in TranslatedAddress.
  97. A return value of FALSE occurs if the translation for the address was
  98. not possible
  99. --*/
  100. {
  101. INTERFACE_TYPE InterfaceType = BusHandler->InterfaceType;
  102. ULONG BusNumber = BusHandler->BusNumber;
  103. PVOID va = 0; // note, this is used for a placeholder
  104. //
  105. // The only buses available on EB66 are an ISA bus and a PCI bus.
  106. // We support any translations for EISA devices as well, though
  107. // if they are true EISA devices they won't even be able to plug into
  108. // the connectors!
  109. //
  110. if (InterfaceType != Isa &&
  111. InterfaceType != Eisa &&
  112. InterfaceType != PCIBus) {
  113. //
  114. // Not on this system return nothing.
  115. //
  116. *AddressSpace = 0;
  117. TranslatedAddress->LowPart = 0;
  118. return(FALSE);
  119. }
  120. //
  121. // Determine the address based on whether the bus address is in I/O space
  122. // or bus memory space.
  123. //
  124. switch ( (ADDRESS_SPACE_TYPE)(*AddressSpace) ) {
  125. case BusMemory: {
  126. //
  127. // The address is in PCI memory space, kernel mode.
  128. //
  129. //jnfix - HAE support here
  130. switch( InterfaceType ) {
  131. case Isa: {
  132. //
  133. // Can't go above 16MB (24 Bits) for Isa Buses
  134. //
  135. if( BusAddress.LowPart >= __16MB ){
  136. *AddressSpace = 0;
  137. TranslatedAddress->LowPart = 0;
  138. return(FALSE);
  139. }
  140. break;
  141. } // case Isa
  142. case PCIBus: {
  143. //
  144. // IMPORTANT: For now we have set HAE set to zero.
  145. //
  146. // MAX PCI sparse memory for us is PCI_MAX_SPARSE_MEMORY_ADDRESS=128MB-1
  147. // MAX PCI dense memory for us is PCI_MAX_DENSE_MEMORY_ADDRESS=2.5GB-1
  148. //
  149. if ( BusAddress.LowPart > PCI_MAX_DENSE_MEMORY_ADDRESS ) {
  150. //
  151. // Unsupported dense PCI bus address.
  152. //
  153. #if HALDBG
  154. DbgPrint ("Unsupported PCI address %x:%x\n",
  155. BusAddress.HighPart,
  156. BusAddress.LowPart);
  157. #endif
  158. *AddressSpace = 0;
  159. TranslatedAddress->LowPart = 0;
  160. return(FALSE);
  161. }
  162. else if( BusAddress.LowPart >= PCI_MIN_DENSE_MEMORY_ADDRESS &&
  163. BusAddress.LowPart <= PCI_MAX_DENSE_MEMORY_ADDRESS ) {
  164. #if HALDBG
  165. DbgPrint ("Translating PCI kernel dense address %x:%x\n",
  166. BusAddress.HighPart,
  167. BusAddress.LowPart);
  168. #endif
  169. //
  170. // Bus Address is in dense PCI memory space
  171. //
  172. //
  173. // QVA, as such, is simply the PCI bus address
  174. //
  175. TranslatedAddress->LowPart = BusAddress.LowPart;
  176. //
  177. // clear high longword for QVA
  178. //
  179. TranslatedAddress->HighPart = 0;
  180. //
  181. // dont let the user call MmMapIoSpace
  182. //
  183. *AddressSpace = 1;
  184. return (TRUE);
  185. }
  186. //
  187. // Bus Address is in sparse PCI memory space
  188. //
  189. #if HALDBG
  190. DbgPrint ("Translating PCI kernel sparse address %x:%x\n",
  191. BusAddress.HighPart,
  192. BusAddress.LowPart);
  193. #endif
  194. break;
  195. } // case PCIBus
  196. case Eisa: {
  197. break;
  198. } // case Eisa
  199. } // switch( InterfaceType )
  200. //
  201. // Start with the base physical address and add the
  202. // bus address by converting it to the physical address.
  203. //
  204. TranslatedAddress->QuadPart = LCA4_PCI_MEMORY_BASE_PHYSICAL;
  205. TranslatedAddress->QuadPart += (BusAddress.LowPart << IO_BIT_SHIFT);
  206. //
  207. // Now call HalCreateQva. This will create a QVA
  208. // that we'll return to the caller. Then we will implicitly set
  209. // AddressSpace to a 1. The caller then will not call MmMapIoSpace
  210. // and will use the address we return as a VA.
  211. //
  212. TranslatedAddress->LowPart =
  213. (ULONG) HalCreateQva( *TranslatedAddress, va);
  214. //
  215. // clear high longword for QVA
  216. //
  217. TranslatedAddress->HighPart = 0;
  218. //
  219. // don't let the user call MmMapIoSpace
  220. //
  221. *AddressSpace = 1;
  222. return(TRUE);
  223. } // case BusMemory
  224. case BusIo: {
  225. //
  226. // The address is in PCI I/O space, kernel mode.
  227. //
  228. switch( InterfaceType ) {
  229. case Isa: {
  230. //
  231. // Can't go above 64KB (16 Bits) for Isa Buses
  232. //
  233. if( BusAddress.LowPart >= __64K ){
  234. *AddressSpace = 0;
  235. TranslatedAddress->LowPart = 0;
  236. return(FALSE);
  237. }
  238. break;
  239. } // case Isa
  240. case PCIBus: {
  241. //
  242. // PCI IO space is always below 16MB (24 Bits) BusAddress
  243. // If the address cannot be mapped, just return FALSE.
  244. //
  245. // IMPORTANT: For now we have set HAXR2 to 0(see ebinitnt.c)
  246. //
  247. if( BusAddress.LowPart >= __16MB ){
  248. *AddressSpace = 0;
  249. TranslatedAddress->LowPart = 0;
  250. return(FALSE);
  251. }
  252. //
  253. // if the BusAddress.LowPart is > 64K then we use the HAER2
  254. // register.
  255. //
  256. break;
  257. } // case PCIBus
  258. case Eisa: {
  259. break;
  260. } // case Eisa
  261. } // switch( InterfaceType )
  262. //
  263. // Start with the base physical address and add the
  264. // bus address by converting it to the physical address.
  265. //
  266. TranslatedAddress->QuadPart = HalpLca4PciIoPhysical();
  267. TranslatedAddress->QuadPart += (BusAddress.LowPart << IO_BIT_SHIFT);
  268. //
  269. // Now call HalCreateQva. This will create a QVA
  270. // that we'll return to the caller. Then we will implicitly set
  271. // AddressSpace to a 1. The caller then will not call MmMapIoSpace
  272. // and will use the address we return as a VA.
  273. TranslatedAddress->LowPart = (ULONG) HalCreateQva( *TranslatedAddress,
  274. va);
  275. TranslatedAddress->HighPart = 0; // clear high longword for QVA
  276. *AddressSpace = 1; // Make sure user doesn't call
  277. // MmMapIoSpace.
  278. return(TRUE);
  279. }
  280. case UserBusMemory: {
  281. //
  282. // The address is in PCI sparse memory space, user mode.
  283. //
  284. //
  285. // Start with the base physical address and add the
  286. // bus address by converting it to the physical address.
  287. //
  288. TranslatedAddress->QuadPart = LCA4_PCI_MEMORY_BASE_PHYSICAL;
  289. TranslatedAddress->QuadPart += (BusAddress.LowPart << IO_BIT_SHIFT);
  290. *AddressSpace = 0; // Let the user call MmMapIoSpace
  291. return(TRUE);
  292. }
  293. case UserBusIo: {
  294. //
  295. // The address is in PCI I/O space, user mode.
  296. //
  297. //
  298. // Start with the base physical address and add the
  299. // bus address by converting it to the physical address.
  300. //
  301. TranslatedAddress->QuadPart = HalpLca4PciIoPhysical();
  302. TranslatedAddress->QuadPart += (BusAddress.LowPart << IO_BIT_SHIFT);
  303. *AddressSpace = 0; // Make sure user can call
  304. // MmMapIoSpace.
  305. return(TRUE);
  306. }
  307. case KernelPciDenseMemory:
  308. case UserPciDenseMemory:
  309. {
  310. //
  311. // The address is in PCI memory space, user mode.
  312. //
  313. //
  314. // Dense space is not supported on Pass 1 LCA4s.
  315. //
  316. if( HalpLca4Revision() == Lca4Pass1 ){
  317. *AddressSpace = 0;
  318. TranslatedAddress->LowPart = 0;
  319. return FALSE;
  320. }
  321. //
  322. // Start with the base physical address and add the
  323. // bus address by converting it to the physical address.
  324. //
  325. TranslatedAddress->QuadPart = HalpLca4PciDensePhysical();
  326. TranslatedAddress->QuadPart += BusAddress.LowPart;
  327. *AddressSpace = 0; // Let the user call MmMapIoSpace
  328. return(TRUE);
  329. }
  330. default: {
  331. //
  332. // Unsupported address space.
  333. *AddressSpace = 0;
  334. TranslatedAddress->LowPart = 0;
  335. return(FALSE);
  336. }
  337. }
  338. }
  339. PVOID
  340. HalCreateQva(
  341. IN PHYSICAL_ADDRESS PA,
  342. IN PVOID VA
  343. )
  344. /*++
  345. Routine Description:
  346. This function is called two ways. First, from HalTranslateBusAddress,
  347. if the caller is going to run in kernel mode and use superpages.
  348. The second way is if the user is going to access in user mode.
  349. MmMapIoSpace or ZwViewMapOfSection will call this.
  350. If the input parameter VA is zero, then we assume super page and build
  351. a QUASI virtual address that is only usable by calling the hal I/O
  352. access routines.
  353. if the input parameter VA is non-zero, we assume the user has either
  354. called MmMapIoSpace or ZwMapViewOfSection and will use the user mode
  355. access macros.
  356. If the PA is not a sparse I/O space address (PCI I/O, PCI Memory),
  357. then return the VA as the QVA.
  358. Arguments:
  359. PA - the physical address generated by HalTranslateBusAddress
  360. VA - the virtual address returned by MmMapIoSpace
  361. Return Value:
  362. The returned value is a quasi virtual address in that it can be
  363. added to and subtracted from, but it cannot be used to access the
  364. bus directly. The top bits are set so that we can trap invalid
  365. accesses in the memory management subsystem. All access should be
  366. done through the Hal Access Routines in *ioacc.s if it was a superpage
  367. kernel mode access. If it is usermode, then the user mode access
  368. macros must be used.
  369. --*/
  370. {
  371. PVOID qva;
  372. //
  373. // If the physical address is not in dense space then perform the
  374. // QVA shuffle.
  375. //
  376. // N.B. - Dense space is not supported for Lca4Pass1.
  377. //
  378. if( (HalpLca4Revision() == Lca4Pass1) ||
  379. (PA.QuadPart < (LONGLONG)HalpLca4PciDensePhysical()) ){
  380. //
  381. // The physical address is within one of the sparse I/O spaces.
  382. //
  383. if (VA == 0) {
  384. qva = (PVOID)(PA.QuadPart >> IO_BIT_SHIFT);
  385. } else {
  386. qva = (PVOID)((ULONG)VA >> IO_BIT_SHIFT);
  387. }
  388. qva = (PVOID)((ULONG)qva | QVA_ENABLE);
  389. return(qva);
  390. }
  391. //
  392. // It is not a sparse I/O space address, return the VA as the QVA
  393. //
  394. return(VA);
  395. }
  396. PVOID
  397. HalDereferenceQva(
  398. PVOID Qva,
  399. INTERFACE_TYPE InterfaceType,
  400. ULONG BusNumber
  401. )
  402. /*++
  403. Routine Description:
  404. This function performs the inverse of the HalCreateQva for I/O addresses
  405. that are memory-mapped (i.e. the quasi-virtual address was created from
  406. a virtual address rather than a physical address).
  407. Arguments:
  408. Qva - Supplies the quasi-virtual address to be converted back to a
  409. virtual address.
  410. InterfaceType - Supplies the interface type of the bus to which the
  411. Qva pertains.
  412. BusNumber - Supplies the bus number of the bus to which the Qva pertains.
  413. Return Value:
  414. The Virtual Address from which the quasi-address was originally created
  415. is returned.
  416. --*/
  417. {
  418. //
  419. // For EB66 we have only 2 bus types:
  420. //
  421. // Isa
  422. // PCIBus
  423. //
  424. // We will allow Eisa as an alias for Isa. All other values not named
  425. // above will be considered bogus.
  426. //
  427. switch (InterfaceType ){
  428. case Isa:
  429. case Eisa:
  430. case PCIBus:
  431. //
  432. // Support dense space: check to see if it's really
  433. // a sparse space QVA.
  434. //
  435. if ( ((ULONG) Qva & QVA_SELECTORS) == QVA_ENABLE )
  436. {
  437. return( (PVOID)( (ULONG)Qva << IO_BIT_SHIFT ) );
  438. }
  439. else
  440. {
  441. return (Qva);
  442. }
  443. break;
  444. default:
  445. return NULL;
  446. }
  447. }