1 /*
2     zr36120_mem.c - Zoran 36120/36125 based framegrabbers
3 
4     Copyright (C) 1998-1999 Pauline Middelink <middelin@polyware.nl>
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 
21 #include <linux/config.h>
22 #include <linux/mm.h>
23 #include <linux/pci.h>
24 #include <linux/wrapper.h>
25 #include <linux/slab.h>
26 #include <linux/module.h>
27 #include <asm/io.h>
28 #ifdef CONFIG_BIGPHYS_AREA
29 #include <linux/bigphysarea.h>
30 #endif
31 
32 #include "zr36120.h"
33 #include "zr36120_mem.h"
34 
35 /*******************************/
36 /* Memory management functions */
37 /*******************************/
38 
bmalloc(unsigned long size)39 void* bmalloc(unsigned long size)
40 {
41 	void* mem;
42 #ifdef CONFIG_BIGPHYS_AREA
43 	mem = bigphysarea_alloc_pages(size/PAGE_SIZE, 1, GFP_KERNEL);
44 #else
45 	/*
46 	 * The following function got a lot of memory at boottime,
47 	 * so we know its always there...
48 	 */
49 	mem = (void*)__get_free_pages(GFP_USER|GFP_DMA,get_order(size));
50 #endif
51 	if (mem) {
52 		unsigned long adr = (unsigned long)mem;
53 		while (size > 0) {
54 			mem_map_reserve(virt_to_page(phys_to_virt(adr)));
55 			adr += PAGE_SIZE;
56 			size -= PAGE_SIZE;
57 		}
58 	}
59 	return mem;
60 }
61 
bfree(void * mem,unsigned long size)62 void bfree(void* mem, unsigned long size)
63 {
64 	if (mem) {
65 		unsigned long adr = (unsigned long)mem;
66 		unsigned long siz = size;
67 		while (siz > 0) {
68 			mem_map_unreserve(virt_to_page(phys_to_virt(adr)));
69 			adr += PAGE_SIZE;
70 			siz -= PAGE_SIZE;
71 		}
72 #ifdef CONFIG_BIGPHYS_AREA
73 		bigphysarea_free_pages(mem);
74 #else
75 		free_pages((unsigned long)mem,get_order(size));
76 #endif
77 	}
78 }
79 
80 MODULE_LICENSE("GPL");
81