~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/sysdev/fsl_85xx_cache_sram.c

Version: ~ [ linux-5.9-rc5 ] ~ [ linux-5.8.10 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.66 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.146 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.198 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.236 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.236 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright 2009-2010 Freescale Semiconductor, Inc.
  3  *
  4  * Simple memory allocator abstraction for QorIQ (P1/P2) based Cache-SRAM
  5  *
  6  * Author: Vivek Mahajan <vivek.mahajan@freescale.com>
  7  *
  8  * This file is derived from the original work done
  9  * by Sylvain Munaut for the Bestcomm SRAM allocator.
 10  *
 11  * This program is free software; you can redistribute  it and/or modify it
 12  * under  the terms of  the GNU General  Public License as published by the
 13  * Free Software Foundation;  either version 2 of the  License, or (at your
 14  * option) any later version.
 15  *
 16  * This program is distributed in the hope that it will be useful,
 17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 19  * GNU General Public License for more details.
 20  *
 21  * You should have received a copy of the GNU General Public License
 22  * along with this program; if not, write to the Free Software
 23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 24  */
 25 
 26 #include <linux/kernel.h>
 27 #include <linux/export.h>
 28 #include <linux/slab.h>
 29 #include <linux/err.h>
 30 #include <linux/of_platform.h>
 31 #include <asm/pgtable.h>
 32 #include <asm/fsl_85xx_cache_sram.h>
 33 
 34 #include "fsl_85xx_cache_ctlr.h"
 35 
 36 struct mpc85xx_cache_sram *cache_sram;
 37 
 38 void *mpc85xx_cache_sram_alloc(unsigned int size,
 39                                 phys_addr_t *phys, unsigned int align)
 40 {
 41         unsigned long offset;
 42         unsigned long flags;
 43 
 44         if (unlikely(cache_sram == NULL))
 45                 return NULL;
 46 
 47         if (!size || (size > cache_sram->size) || (align > cache_sram->size)) {
 48                 pr_err("%s(): size(=%x) or align(=%x) zero or too big\n",
 49                         __func__, size, align);
 50                 return NULL;
 51         }
 52 
 53         if ((align & (align - 1)) || align <= 1) {
 54                 pr_err("%s(): align(=%x) must be power of two and >1\n",
 55                         __func__, align);
 56                 return NULL;
 57         }
 58 
 59         spin_lock_irqsave(&cache_sram->lock, flags);
 60         offset = rh_alloc_align(cache_sram->rh, size, align, NULL);
 61         spin_unlock_irqrestore(&cache_sram->lock, flags);
 62 
 63         if (IS_ERR_VALUE(offset))
 64                 return NULL;
 65 
 66         *phys = cache_sram->base_phys + offset;
 67 
 68         return (unsigned char *)cache_sram->base_virt + offset;
 69 }
 70 EXPORT_SYMBOL(mpc85xx_cache_sram_alloc);
 71 
 72 void mpc85xx_cache_sram_free(void *ptr)
 73 {
 74         unsigned long flags;
 75         BUG_ON(!ptr);
 76 
 77         spin_lock_irqsave(&cache_sram->lock, flags);
 78         rh_free(cache_sram->rh, ptr - cache_sram->base_virt);
 79         spin_unlock_irqrestore(&cache_sram->lock, flags);
 80 }
 81 EXPORT_SYMBOL(mpc85xx_cache_sram_free);
 82 
 83 int __init instantiate_cache_sram(struct platform_device *dev,
 84                 struct sram_parameters sram_params)
 85 {
 86         int ret = 0;
 87 
 88         if (cache_sram) {
 89                 dev_err(&dev->dev, "Already initialized cache-sram\n");
 90                 return -EBUSY;
 91         }
 92 
 93         cache_sram = kzalloc(sizeof(struct mpc85xx_cache_sram), GFP_KERNEL);
 94         if (!cache_sram) {
 95                 dev_err(&dev->dev, "Out of memory for cache_sram structure\n");
 96                 return -ENOMEM;
 97         }
 98 
 99         cache_sram->base_phys = sram_params.sram_offset;
100         cache_sram->size = sram_params.sram_size;
101 
102         if (!request_mem_region(cache_sram->base_phys, cache_sram->size,
103                                                 "fsl_85xx_cache_sram")) {
104                 dev_err(&dev->dev, "%s: request memory failed\n",
105                                 dev->dev.of_node->full_name);
106                 ret = -ENXIO;
107                 goto out_free;
108         }
109 
110         cache_sram->base_virt = ioremap_prot(cache_sram->base_phys,
111                                 cache_sram->size, _PAGE_COHERENT | PAGE_KERNEL);
112         if (!cache_sram->base_virt) {
113                 dev_err(&dev->dev, "%s: ioremap_prot failed\n",
114                                 dev->dev.of_node->full_name);
115                 ret = -ENOMEM;
116                 goto out_release;
117         }
118 
119         cache_sram->rh = rh_create(sizeof(unsigned int));
120         if (IS_ERR(cache_sram->rh)) {
121                 dev_err(&dev->dev, "%s: Unable to create remote heap\n",
122                                 dev->dev.of_node->full_name);
123                 ret = PTR_ERR(cache_sram->rh);
124                 goto out_unmap;
125         }
126 
127         rh_attach_region(cache_sram->rh, 0, cache_sram->size);
128         spin_lock_init(&cache_sram->lock);
129 
130         dev_info(&dev->dev, "[base:0x%llx, size:0x%x] configured and loaded\n",
131                 (unsigned long long)cache_sram->base_phys, cache_sram->size);
132 
133         return 0;
134 
135 out_unmap:
136         iounmap(cache_sram->base_virt);
137 
138 out_release:
139         release_mem_region(cache_sram->base_phys, cache_sram->size);
140 
141 out_free:
142         kfree(cache_sram);
143         return ret;
144 }
145 
146 void remove_cache_sram(struct platform_device *dev)
147 {
148         BUG_ON(!cache_sram);
149 
150         rh_detach_region(cache_sram->rh, 0, cache_sram->size);
151         rh_destroy(cache_sram->rh);
152 
153         iounmap(cache_sram->base_virt);
154         release_mem_region(cache_sram->base_phys, cache_sram->size);
155 
156         kfree(cache_sram);
157         cache_sram = NULL;
158 
159         dev_info(&dev->dev, "MPC85xx Cache-SRAM driver unloaded\n");
160 }
161 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp