xref: /linux/arch/powerpc/platforms/cell/spufs/lscsa_alloc.c (revision b85d45947951d23cb22d90caecf4c1eb81342c96)
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 
21 #undef DEBUG
22 
23 #include <linux/kernel.h>
24 #include <linux/mm.h>
25 #include <linux/slab.h>
26 #include <linux/vmalloc.h>
27 
28 #include <asm/spu.h>
29 #include <asm/spu_csa.h>
30 #include <asm/mmu.h>
31 
32 #include "spufs.h"
33 
34 int spu_alloc_lscsa(struct spu_state *csa)
35 {
36 	struct spu_lscsa *lscsa;
37 	unsigned char *p;
38 
39 	lscsa = vzalloc(sizeof(struct spu_lscsa));
40 	if (!lscsa)
41 		return -ENOMEM;
42 	csa->lscsa = lscsa;
43 
44 	/* Set LS pages reserved to allow for user-space mapping. */
45 	for (p = lscsa->ls; p < lscsa->ls + LS_SIZE; p += PAGE_SIZE)
46 		SetPageReserved(vmalloc_to_page(p));
47 
48 	return 0;
49 }
50 
51 void spu_free_lscsa(struct spu_state *csa)
52 {
53 	/* Clear reserved bit before vfree. */
54 	unsigned char *p;
55 
56 	if (csa->lscsa == NULL)
57 		return;
58 
59 	for (p = csa->lscsa->ls; p < csa->lscsa->ls + LS_SIZE; p += PAGE_SIZE)
60 		ClearPageReserved(vmalloc_to_page(p));
61 
62 	vfree(csa->lscsa);
63 }
64