blob: b847e94035664dbdd6f5d9c3c4223d27c921f81d [file] [log] [blame]
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +10001/*
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +100026#include <linux/vmalloc.h>
27
28#include <asm/spu.h>
29#include <asm/spu_csa.h>
30#include <asm/mmu.h>
31
Jeremy Kerr7cd58e42007-12-20 16:39:59 +090032#include "spufs.h"
33
Michael Ellermanf444f1f2015-08-07 16:19:44 +100034int spu_alloc_lscsa(struct spu_state *csa)
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +100035{
36 struct spu_lscsa *lscsa;
37 unsigned char *p;
38
Jesper Juhl467d93a2010-10-30 08:10:41 +000039 lscsa = vzalloc(sizeof(struct spu_lscsa));
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +100040 if (!lscsa)
41 return -ENOMEM;
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +100042 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
Michael Ellermanf444f1f2015-08-07 16:19:44 +100051void spu_free_lscsa(struct spu_state *csa)
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +100052{
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}