Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * SPU local store allocation routines
0004  *
0005  * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
0006  */
0007 
0008 #undef DEBUG
0009 
0010 #include <linux/kernel.h>
0011 #include <linux/mm.h>
0012 #include <linux/slab.h>
0013 #include <linux/vmalloc.h>
0014 
0015 #include <asm/spu.h>
0016 #include <asm/spu_csa.h>
0017 #include <asm/mmu.h>
0018 
0019 #include "spufs.h"
0020 
0021 int spu_alloc_lscsa(struct spu_state *csa)
0022 {
0023     struct spu_lscsa *lscsa;
0024     unsigned char *p;
0025 
0026     lscsa = vzalloc(sizeof(*lscsa));
0027     if (!lscsa)
0028         return -ENOMEM;
0029     csa->lscsa = lscsa;
0030 
0031     /* Set LS pages reserved to allow for user-space mapping. */
0032     for (p = lscsa->ls; p < lscsa->ls + LS_SIZE; p += PAGE_SIZE)
0033         SetPageReserved(vmalloc_to_page(p));
0034 
0035     return 0;
0036 }
0037 
0038 void spu_free_lscsa(struct spu_state *csa)
0039 {
0040     /* Clear reserved bit before vfree. */
0041     unsigned char *p;
0042 
0043     if (csa->lscsa == NULL)
0044         return;
0045 
0046     for (p = csa->lscsa->ls; p < csa->lscsa->ls + LS_SIZE; p += PAGE_SIZE)
0047         ClearPageReserved(vmalloc_to_page(p));
0048 
0049     vfree(csa->lscsa);
0050 }