4 * @brief All @b CDCM memory handling is located here.
6 * @author Georgievskiy Yury, Alain Gagnaire. CERN AB/CO.
8 * @date Created on 17/02/2007
10 * Many thanks to Julian Lewis and Nicolas de Metz-Noblat.
14 #include "general_drvr.h" /* various defs */
18 /* CDCM global variables (declared in the cdcmDrvr.c module) */
19 extern cdcmStatics_t cdcmStatT
; /* CDCM statics table */
22 * @brief Release previously allocated memory
24 * @param pntr - mem pointer to release, returned by @e cdcm_mem_alloc.
26 void cdcm_mem_free(void *addr
)
28 struct cdcm_mem_header
*buf
= addr
;
34 realsize
= buf
->size
+ sizeof(*buf
);
36 if (realsize
> MEM_BOUND
)
43 * @brief Allocates memory.
45 * @param size - size in @b bytes
46 * @param flags - memory flags (see @e cdcmm_t definition
47 * for more info on the possible flags)
49 * @return -ENOMEM - if fails.
50 * @return allocated memory pointer - if success.
52 void *cdcm_mem_alloc(ssize_t size
, int flags
)
54 struct cdcm_mem_header
*buf
;
55 size_t realsize
= size
+ sizeof(*buf
);
58 * For large buffers we use vmalloc, because kmalloc allocates
59 * physically contiguous pages.
61 if (realsize
> MEM_BOUND
)
62 buf
= vmalloc(realsize
);
64 buf
= kmalloc(realsize
, GFP_KERNEL
);
67 PRNT_ERR(cdcmStatT
.cdcm_ipl
, "Can't alloc 0x%x bytes", realsize
);
68 return ERR_PTR(-ENOMEM
);
76 * get_phys - get physical address of a virtual address !TODO!
78 * @param vaddr: virtual address
80 * returns the physical address onto which the given virtual address is mapped.
81 * Some hardware devices may require a corresponding physical address
82 * if they, for example, access physical memory directly (DMA) without the
83 * benefit of the MMU. The value returned by get_phys minus PHYSBASE may be used
88 char *get_phys(long vaddr
)
95 * mem_lock - guarantees address range is in real memory
97 * @param tjob: process ID that wants to lock memory
98 * @param start:virtual start address, in bytes
99 * @param size: size of the region of memory to lock, in bytes
101 * mem_lock guarantees that a region of virtual memory is locked into physical
102 * memory. mem_lock returns OK if it can lock all the requested memory
103 * otherwise it will return SYSERR.
107 int mem_lock(int tjob
, char *start
, unsigned long size
)
114 * mem_unlock - frees real memory for swapping !TODO!
116 * @param tjob: process ID that wants to lock memory
117 * @param start: is the virtual start address, in bytes
118 * @param size: is the size of the region of memory to lock, in bytes
119 * @param dirty: if dirty is non 0 then the entire section of memory from
120 * start to size will be marked as dirty. Dirty pages will be written to disk
121 * by the VM mechanism in the kernel before they are released.
123 * mem_unlock unlocks the previously locked region of virtual memory which
124 * allows the memory to be swapped. mem_unlock returns OK if the region
125 * has been successfully unlocked otherwise it will return SYSERR
132 * get1page - get one page of physical memory
134 * allocates one page of physical memory and returns a virtual address
135 * which can be used to access it.
141 return (char *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
145 * @brief free a page allocated with get1page()
147 * @param addr - address of the page
149 void free1page(void *addr
)
151 return free_page((unsigned long)addr
);