zr36120_mem.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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