Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/mm.h> |
| 22 | #include <linux/pci.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <asm/io.h> |
| 26 | #ifdef CONFIG_BIGPHYS_AREA |
| 27 | #include <linux/bigphysarea.h> |
| 28 | #endif |
| 29 | |
| 30 | #include "zr36120.h" |
| 31 | #include "zr36120_mem.h" |
| 32 | |
| 33 | /*******************************/ |
| 34 | /* Memory management functions */ |
| 35 | /*******************************/ |
| 36 | |
| 37 | void* bmalloc(unsigned long size) |
| 38 | { |
| 39 | void* mem; |
| 40 | #ifdef CONFIG_BIGPHYS_AREA |
| 41 | mem = bigphysarea_alloc_pages(size/PAGE_SIZE, 1, GFP_KERNEL); |
| 42 | #else |
| 43 | /* |
| 44 | * The following function got a lot of memory at boottime, |
| 45 | * so we know its always there... |
| 46 | */ |
| 47 | mem = (void*)__get_free_pages(GFP_USER|GFP_DMA,get_order(size)); |
| 48 | #endif |
| 49 | if (mem) { |
| 50 | unsigned long adr = (unsigned long)mem; |
| 51 | while (size > 0) { |
| 52 | SetPageReserved(virt_to_page(phys_to_virt(adr))); |
| 53 | adr += PAGE_SIZE; |
| 54 | size -= PAGE_SIZE; |
| 55 | } |
| 56 | } |
| 57 | return mem; |
| 58 | } |
| 59 | |
| 60 | void bfree(void* mem, unsigned long size) |
| 61 | { |
| 62 | if (mem) { |
| 63 | unsigned long adr = (unsigned long)mem; |
| 64 | unsigned long siz = size; |
| 65 | while (siz > 0) { |
| 66 | ClearPageReserved(virt_to_page(phys_to_virt(adr))); |
| 67 | adr += PAGE_SIZE; |
| 68 | siz -= PAGE_SIZE; |
| 69 | } |
| 70 | #ifdef CONFIG_BIGPHYS_AREA |
| 71 | bigphysarea_free_pages(mem); |
| 72 | #else |
| 73 | free_pages((unsigned long)mem,get_order(size)); |
| 74 | #endif |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | MODULE_LICENSE("GPL"); |