diva_dma.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. *
  3. Copyright (c) Eicon Networks, 2002.
  4. *
  5. This source file is supplied for the use with
  6. Eicon Networks range of DIVA Server Adapters.
  7. *
  8. Eicon File Revision : 2.1
  9. *
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14. *
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
  17. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. See the GNU General Public License for more details.
  19. *
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include "platform.h"
  26. #include "diva_dma.h"
  27. /*
  28. Every entry has length of PAGE_SIZE
  29. and represents one single physical page
  30. */
  31. struct _diva_dma_map_entry {
  32. int busy;
  33. dword phys_bus_addr; /* 32bit address as seen by the card */
  34. void *local_ram_addr; /* local address as seen by the host */
  35. void *addr_handle; /* handle uset to free allocated memory */
  36. };
  37. /*
  38. Create local mapping structure and init it to default state
  39. */
  40. struct _diva_dma_map_entry *diva_alloc_dma_map(void *os_context, int nentries) {
  41. diva_dma_map_entry_t *pmap = diva_os_malloc(0, sizeof(*pmap) * (nentries + 1));
  42. if (pmap)
  43. memset(pmap, 0, sizeof(*pmap) * (nentries + 1));
  44. return pmap;
  45. }
  46. /*
  47. Free local map (context should be freed before) if any
  48. */
  49. void diva_free_dma_mapping(struct _diva_dma_map_entry *pmap) {
  50. if (pmap) {
  51. diva_os_free(0, pmap);
  52. }
  53. }
  54. /*
  55. Set information saved on the map entry
  56. */
  57. void diva_init_dma_map_entry(struct _diva_dma_map_entry *pmap,
  58. int nr, void *virt, dword phys,
  59. void *addr_handle) {
  60. pmap[nr].phys_bus_addr = phys;
  61. pmap[nr].local_ram_addr = virt;
  62. pmap[nr].addr_handle = addr_handle;
  63. }
  64. /*
  65. Allocate one single entry in the map
  66. */
  67. int diva_alloc_dma_map_entry(struct _diva_dma_map_entry *pmap) {
  68. int i;
  69. for (i = 0; (pmap && pmap[i].local_ram_addr); i++) {
  70. if (!pmap[i].busy) {
  71. pmap[i].busy = 1;
  72. return (i);
  73. }
  74. }
  75. return (-1);
  76. }
  77. /*
  78. Free one single entry in the map
  79. */
  80. void diva_free_dma_map_entry(struct _diva_dma_map_entry *pmap, int nr) {
  81. pmap[nr].busy = 0;
  82. }
  83. /*
  84. Get information saved on the map entry
  85. */
  86. void diva_get_dma_map_entry(struct _diva_dma_map_entry *pmap, int nr,
  87. void **pvirt, dword *pphys) {
  88. *pphys = pmap[nr].phys_bus_addr;
  89. *pvirt = pmap[nr].local_ram_addr;
  90. }
  91. void *diva_get_entry_handle(struct _diva_dma_map_entry *pmap, int nr) {
  92. return (pmap[nr].addr_handle);
  93. }