zr36120_mem.c 2.0 KB

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