palloc.c 1.5 KB

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