zr36120_mem.c 2.1 KB

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