1
0

vmm_iomap.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * VMM IO map table
  3. *
  4. * COPYRIGHT (C) 2013, Shanghai Real-Thread Technology Co., Ltd
  5. *
  6. * This file is part of RT-Thread (http://www.rt-thread.org)
  7. * Maintainer: bernard.xiong <bernard.xiong at gmail.com>
  8. *
  9. * All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. *
  25. * Change Logs:
  26. * Date Author Notes
  27. * 2013-06-15 Bernard the first verion
  28. */
  29. #include <rtthread.h>
  30. #include "vmm.h"
  31. static struct vmm_iomap _vmm_iomap[RT_VMM_IOMAP_MAXNR];
  32. void vmm_iomap_init(struct vmm_iomap *iomap)
  33. {
  34. rt_memcpy(_vmm_iomap, iomap, sizeof(_vmm_iomap));
  35. }
  36. /* find virtual address according to name */
  37. unsigned long vmm_find_iomap(const char *name)
  38. {
  39. int i;
  40. for (i = 0; i < ARRAY_SIZE(_vmm_iomap); i++)
  41. {
  42. if (rt_strcmp(_vmm_iomap[i].name, name) == 0)
  43. return (unsigned long)_vmm_iomap[i].va;
  44. }
  45. return 0;
  46. }
  47. /* find virtual address according to physcal address */
  48. unsigned long vmm_find_iomap_by_pa(unsigned long pa)
  49. {
  50. int i;
  51. for (i = 0; i < ARRAY_SIZE(_vmm_iomap); i++)
  52. {
  53. if (_vmm_iomap[i].pa == pa)
  54. return (unsigned long)_vmm_iomap[i].va;
  55. }
  56. return 0;
  57. }