lscsa_alloc.c 982 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * SPU local store allocation routines
  4. *
  5. * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
  6. */
  7. #undef DEBUG
  8. #include <linux/kernel.h>
  9. #include <linux/mm.h>
  10. #include <linux/slab.h>
  11. #include <linux/vmalloc.h>
  12. #include <asm/spu.h>
  13. #include <asm/spu_csa.h>
  14. #include <asm/mmu.h>
  15. #include "spufs.h"
  16. int spu_alloc_lscsa(struct spu_state *csa)
  17. {
  18. struct spu_lscsa *lscsa;
  19. unsigned char *p;
  20. lscsa = vzalloc(sizeof(*lscsa));
  21. if (!lscsa)
  22. return -ENOMEM;
  23. csa->lscsa = lscsa;
  24. /* Set LS pages reserved to allow for user-space mapping. */
  25. for (p = lscsa->ls; p < lscsa->ls + LS_SIZE; p += PAGE_SIZE)
  26. SetPageReserved(vmalloc_to_page(p));
  27. return 0;
  28. }
  29. void spu_free_lscsa(struct spu_state *csa)
  30. {
  31. /* Clear reserved bit before vfree. */
  32. unsigned char *p;
  33. if (csa->lscsa == NULL)
  34. return;
  35. for (p = csa->lscsa->ls; p < csa->lscsa->ls + LS_SIZE; p += PAGE_SIZE)
  36. ClearPageReserved(vmalloc_to_page(p));
  37. vfree(csa->lscsa);
  38. }