home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lxapi32.zip / Lib32 / lxioremap.cpp < prev    next >
C/C++ Source or Header  |  2002-04-26  |  2KB  |  93 lines

  1. /* $Id: lxioremap.cpp,v 1.2 2002/04/26 23:09:23 smilcke Exp $ */
  2.  
  3. /*
  4.  * ioremap.c
  5.  * Autor:               Stefan Milcke
  6.  * Erstellt am:         08.11.2001
  7.  * Letzte Aenderung am: 15.12.2001
  8.  *
  9. */
  10.  
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define INCL_NOPMAPI
  15. #define INCL_DOSERRORS
  16. #include <os2.h>
  17. }
  18. #include <devhelp.h>
  19. #include <ldefos2.h>
  20. #ifdef KEE
  21. #include <kee.h>
  22. #endif
  23.  
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27.  
  28. struct mapped_mem
  29. {
  30.  SEL sel;
  31.  unsigned long linaddr;
  32. };
  33.  
  34. struct mapped_mem mmem[MAX_GDTSELECTORS]={0};
  35.  
  36. //---------------------------------- ioremap -----------------------------------
  37. extern "C" unsigned short allocGDTSelector(void);
  38. extern "C" int freeGDTSelector(unsigned short selector);
  39.  
  40. unsigned long ioremap(unsigned long addr,unsigned short usSize)
  41. {
  42.  unsigned long linaddr=0;
  43.  SEL sel=0;
  44.  sel=(SEL)allocGDTSelector();
  45.  if(!DevPhysToGDTSelector((PHYSICAL)addr,(WORD16)usSize,sel))
  46.  {
  47.   if(DevVirtToLin(sel
  48.                   ,0
  49. #ifdef KEE
  50.                   ,(unsigned char * __far *)&linaddr))
  51. #else
  52.                   ,(unsigned char __near **)&linaddr))
  53. #endif
  54.    linaddr=0;
  55.  }
  56.  if(!linaddr)
  57.   freeGDTSelector(sel);
  58.  else
  59.  {
  60.   int i;
  61.   for(i=0;i<MAX_GDTSELECTORS;i++)
  62.   {
  63.    if(!(mmem[i].sel))
  64.    {
  65.     mmem[i].sel=sel;
  66.     mmem[i].linaddr=linaddr;
  67.     break;
  68.    }
  69.   }
  70.  }
  71.  return linaddr;
  72. }
  73.  
  74. //---------------------------------- iounmap -----------------------------------
  75. #pragma off(unreferenced)
  76. void iounmap(void *addr)
  77. #pragma on(unreferenced)
  78. {
  79.  int i;
  80.  for(i=0;i<MAX_GDTSELECTORS;i++)
  81.  {
  82.   if(mmem[i].sel && mmem[i].linaddr==(unsigned long)addr)
  83.   {
  84.    freeGDTSelector(mmem[i].sel);
  85.    mmem[i].sel=0;
  86.    break;
  87.   }
  88.  }
  89. }
  90.  
  91. #ifdef __cplusplus
  92. }
  93. #endif