lscsa_alloc.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * SPU local store allocation routines
  3. *
  4. * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #undef DEBUG
  21. #include <linux/kernel.h>
  22. #include <linux/mm.h>
  23. #include <linux/slab.h>
  24. #include <linux/vmalloc.h>
  25. #include <asm/spu.h>
  26. #include <asm/spu_csa.h>
  27. #include <asm/mmu.h>
  28. #include "spufs.h"
  29. int spu_alloc_lscsa(struct spu_state *csa)
  30. {
  31. struct spu_lscsa *lscsa;
  32. unsigned char *p;
  33. lscsa = vzalloc(sizeof(struct spu_lscsa));
  34. if (!lscsa)
  35. return -ENOMEM;
  36. csa->lscsa = lscsa;
  37. /* Set LS pages reserved to allow for user-space mapping. */
  38. for (p = lscsa->ls; p < lscsa->ls + LS_SIZE; p += PAGE_SIZE)
  39. SetPageReserved(vmalloc_to_page(p));
  40. return 0;
  41. }
  42. void spu_free_lscsa(struct spu_state *csa)
  43. {
  44. /* Clear reserved bit before vfree. */
  45. unsigned char *p;
  46. if (csa->lscsa == NULL)
  47. return;
  48. for (p = csa->lscsa->ls; p < csa->lscsa->ls + LS_SIZE; p += PAGE_SIZE)
  49. ClearPageReserved(vmalloc_to_page(p));
  50. vfree(csa->lscsa);
  51. }