Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 26 | #include <linux/vmalloc.h> |
| 27 | |
| 28 | #include <asm/spu.h> |
| 29 | #include <asm/spu_csa.h> |
| 30 | #include <asm/mmu.h> |
| 31 | |
Jeremy Kerr | 7cd58e4 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 32 | #include "spufs.h" |
| 33 | |
Michael Ellerman | f444f1f | 2015-08-07 16:19:44 +1000 | [diff] [blame] | 34 | int spu_alloc_lscsa(struct spu_state *csa) |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 35 | { |
| 36 | struct spu_lscsa *lscsa; |
| 37 | unsigned char *p; |
| 38 | |
Jesper Juhl | 467d93a | 2010-10-30 08:10:41 +0000 | [diff] [blame] | 39 | lscsa = vzalloc(sizeof(struct spu_lscsa)); |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 40 | if (!lscsa) |
| 41 | return -ENOMEM; |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 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 | |
Michael Ellerman | f444f1f | 2015-08-07 16:19:44 +1000 | [diff] [blame] | 51 | void spu_free_lscsa(struct spu_state *csa) |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 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 | } |