1 /* palloc.c: Memory allocation from the Sun PROM.
2 *
3 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
4 */
5
6 #include <asm/openprom.h>
7 #include <asm/oplib.h>
8
9 /* You should not call these routines after memory management
10 * has been initialized in the kernel, if fact you should not
11 * use these if at all possible in the kernel. They are mainly
12 * to be used for a bootloader for temporary allocations which
13 * it will free before jumping into the kernel it has loaded.
14 *
15 * Also, these routines don't work on V0 proms, only V2 and later.
16 */
17
18 /* Allocate a chunk of memory of size 'num_bytes' giving a suggestion
19 * of virtual_hint as the preferred virtual base address of this chunk.
20 * There are no guarentees that you will get the allocation, or that
21 * the prom will abide by your "hint". So check your return value.
22 */
23 char *
24 prom_alloc(char *virtual_hint, unsigned int num_bytes)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
25 {
26 if(prom_vers == PROM_V0) return (char *) 0x0;
27 if(num_bytes == 0x0) return (char *) 0x0;
28 return (*(romvec->pv_v2devops.v2_dumb_mem_alloc))(virtual_hint, num_bytes);
29 }
30
31 /* Free a previously allocated chunk back to the prom at virtual address
32 * 'vaddr' of size 'num_bytes'. NOTE: This vaddr is not the hint you
33 * used for the allocation, but the virtual address the prom actually
34 * returned to you. They may be have been the same, they may have not,
35 * doesn't matter.
36 */
37 void
38 prom_free(char *vaddr, unsigned int num_bytes)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
39 {
40 if((prom_vers == PROM_V0) || (num_bytes == 0x0)) return;
41 (*(romvec->pv_v2devops.v2_dumb_mem_free))(vaddr, num_bytes);
42 return;
43 }