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