1*de6cc651SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2f1fa74f4SBenjamin Herrenschmidt /* 3f1fa74f4SBenjamin Herrenschmidt * SPU local store allocation routines 4f1fa74f4SBenjamin Herrenschmidt * 5f1fa74f4SBenjamin Herrenschmidt * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. 6f1fa74f4SBenjamin Herrenschmidt */ 7f1fa74f4SBenjamin Herrenschmidt 8f1fa74f4SBenjamin Herrenschmidt #undef DEBUG 9f1fa74f4SBenjamin Herrenschmidt 10f1fa74f4SBenjamin Herrenschmidt #include <linux/kernel.h> 11f1fa74f4SBenjamin Herrenschmidt #include <linux/mm.h> 125a0e3ad6STejun Heo #include <linux/slab.h> 13f1fa74f4SBenjamin Herrenschmidt #include <linux/vmalloc.h> 14f1fa74f4SBenjamin Herrenschmidt 15f1fa74f4SBenjamin Herrenschmidt #include <asm/spu.h> 16f1fa74f4SBenjamin Herrenschmidt #include <asm/spu_csa.h> 17f1fa74f4SBenjamin Herrenschmidt #include <asm/mmu.h> 18f1fa74f4SBenjamin Herrenschmidt 197cd58e43SJeremy Kerr #include "spufs.h" 207cd58e43SJeremy Kerr spu_alloc_lscsa(struct spu_state * csa)21f444f1f8SMichael Ellermanint spu_alloc_lscsa(struct spu_state *csa) 22f1fa74f4SBenjamin Herrenschmidt { 23f1fa74f4SBenjamin Herrenschmidt struct spu_lscsa *lscsa; 24f1fa74f4SBenjamin Herrenschmidt unsigned char *p; 25f1fa74f4SBenjamin Herrenschmidt 26a0828cf5SMarkus Elfring lscsa = vzalloc(sizeof(*lscsa)); 27f1fa74f4SBenjamin Herrenschmidt if (!lscsa) 28f1fa74f4SBenjamin Herrenschmidt return -ENOMEM; 29f1fa74f4SBenjamin Herrenschmidt csa->lscsa = lscsa; 30f1fa74f4SBenjamin Herrenschmidt 31f1fa74f4SBenjamin Herrenschmidt /* Set LS pages reserved to allow for user-space mapping. */ 32f1fa74f4SBenjamin Herrenschmidt for (p = lscsa->ls; p < lscsa->ls + LS_SIZE; p += PAGE_SIZE) 33f1fa74f4SBenjamin Herrenschmidt SetPageReserved(vmalloc_to_page(p)); 34f1fa74f4SBenjamin Herrenschmidt 35f1fa74f4SBenjamin Herrenschmidt return 0; 36f1fa74f4SBenjamin Herrenschmidt } 37f1fa74f4SBenjamin Herrenschmidt spu_free_lscsa(struct spu_state * csa)38f444f1f8SMichael Ellermanvoid spu_free_lscsa(struct spu_state *csa) 39f1fa74f4SBenjamin Herrenschmidt { 40f1fa74f4SBenjamin Herrenschmidt /* Clear reserved bit before vfree. */ 41f1fa74f4SBenjamin Herrenschmidt unsigned char *p; 42f1fa74f4SBenjamin Herrenschmidt 43f1fa74f4SBenjamin Herrenschmidt if (csa->lscsa == NULL) 44f1fa74f4SBenjamin Herrenschmidt return; 45f1fa74f4SBenjamin Herrenschmidt 46f1fa74f4SBenjamin Herrenschmidt for (p = csa->lscsa->ls; p < csa->lscsa->ls + LS_SIZE; p += PAGE_SIZE) 47f1fa74f4SBenjamin Herrenschmidt ClearPageReserved(vmalloc_to_page(p)); 48f1fa74f4SBenjamin Herrenschmidt 49f1fa74f4SBenjamin Herrenschmidt vfree(csa->lscsa); 50f1fa74f4SBenjamin Herrenschmidt } 51