diva_dma.c 2.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3

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