• Home
  • Raw
  • Download

Lines Matching full:ocmem

3  * The On Chip Memory (OCMEM) allocator allows various clients to allocate
4 * memory from OCMEM based on performance, latency and power requirements.
23 #include <soc/qcom/ocmem.h>
52 struct ocmem { struct
108 static inline void ocmem_write(struct ocmem *ocmem, u32 reg, u32 data) in ocmem_write() argument
110 writel(data, ocmem->mmio + reg); in ocmem_write()
113 static inline u32 ocmem_read(struct ocmem *ocmem, u32 reg) in ocmem_read() argument
115 return readl(ocmem->mmio + reg); in ocmem_read()
118 static void update_ocmem(struct ocmem *ocmem) in update_ocmem() argument
124 for (i = 0; i < ocmem->config->num_regions; i++) { in update_ocmem()
125 struct ocmem_region *region = &ocmem->regions[i]; in update_ocmem()
131 dev_dbg(ocmem->dev, "ocmem_region_mode_control %x\n", in update_ocmem()
133 ocmem_write(ocmem, OCMEM_REG_REGION_MODE_CTL, region_mode_ctrl); in update_ocmem()
136 for (i = 0; i < ocmem->config->num_regions; i++) { in update_ocmem()
137 struct ocmem_region *region = &ocmem->regions[i]; in update_ocmem()
145 ocmem_write(ocmem, OCMEM_REG_PSGSC_CTL(i), data); in update_ocmem()
149 static unsigned long phys_to_offset(struct ocmem *ocmem, in phys_to_offset() argument
152 if (addr < ocmem->memory->start || addr >= ocmem->memory->end) in phys_to_offset()
155 return addr - ocmem->memory->start; in phys_to_offset()
158 static unsigned long device_address(struct ocmem *ocmem, in device_address() argument
165 return phys_to_offset(ocmem, addr); in device_address()
168 static void update_range(struct ocmem *ocmem, struct ocmem_buf *buf, in update_range() argument
174 for (i = 0; i < ocmem->config->num_regions; i++) { in update_range()
175 struct ocmem_region *region = &ocmem->regions[i]; in update_range()
189 update_ocmem(ocmem); in update_range()
192 struct ocmem *of_get_ocmem(struct device *dev) in of_get_ocmem()
196 struct ocmem *ocmem; in of_get_ocmem() local
213 ocmem = platform_get_drvdata(pdev); in of_get_ocmem()
214 if (!ocmem) { in of_get_ocmem()
215 dev_err(dev, "Cannot get ocmem\n"); in of_get_ocmem()
219 return ocmem; in of_get_ocmem()
223 struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client, in ocmem_allocate() argument
236 if (test_and_set_bit_lock(BIT(client), &ocmem->active_allocations)) in ocmem_allocate()
246 buf->addr = device_address(ocmem, client, buf->offset); in ocmem_allocate()
249 update_range(ocmem, buf, CORE_ON, WIDE_MODE); in ocmem_allocate()
255 dev_err(ocmem->dev, "could not lock: %d\n", ret); in ocmem_allocate()
260 ocmem_write(ocmem, OCMEM_REG_GFX_MPU_START, buf->offset); in ocmem_allocate()
261 ocmem_write(ocmem, OCMEM_REG_GFX_MPU_END, in ocmem_allocate()
265 dev_dbg(ocmem->dev, "using %ldK of OCMEM at 0x%08lx for client %d\n", in ocmem_allocate()
273 clear_bit_unlock(BIT(client), &ocmem->active_allocations); in ocmem_allocate()
279 void ocmem_free(struct ocmem *ocmem, enum ocmem_client client, in ocmem_free() argument
286 update_range(ocmem, buf, CLK_OFF, MODE_DEFAULT); in ocmem_free()
294 dev_err(ocmem->dev, "could not unlock: %d\n", ret); in ocmem_free()
296 ocmem_write(ocmem, OCMEM_REG_GFX_MPU_START, 0x0); in ocmem_free()
297 ocmem_write(ocmem, OCMEM_REG_GFX_MPU_END, 0x0); in ocmem_free()
302 clear_bit_unlock(BIT(client), &ocmem->active_allocations); in ocmem_free()
312 struct ocmem *ocmem; in ocmem_dev_probe() local
317 ocmem = devm_kzalloc(dev, sizeof(*ocmem), GFP_KERNEL); in ocmem_dev_probe()
318 if (!ocmem) in ocmem_dev_probe()
321 ocmem->dev = dev; in ocmem_dev_probe()
322 ocmem->config = device_get_match_data(dev); in ocmem_dev_probe()
333 ocmem->mmio = devm_ioremap_resource(&pdev->dev, res); in ocmem_dev_probe()
334 if (IS_ERR(ocmem->mmio)) { in ocmem_dev_probe()
336 return PTR_ERR(ocmem->mmio); in ocmem_dev_probe()
339 ocmem->memory = platform_get_resource_byname(pdev, IORESOURCE_MEM, in ocmem_dev_probe()
341 if (!ocmem->memory) { in ocmem_dev_probe()
351 dev_info(ocmem->dev, "Failed to enable clocks\n"); in ocmem_dev_probe()
364 reg = ocmem_read(ocmem, OCMEM_REG_HW_VERSION); in ocmem_dev_probe()
365 dev_dbg(dev, "OCMEM hardware version: %lu.%lu.%lu\n", in ocmem_dev_probe()
370 reg = ocmem_read(ocmem, OCMEM_REG_HW_PROFILE); in ocmem_dev_probe()
371 ocmem->num_ports = OCMEM_HW_PROFILE_NUM_PORTS(reg); in ocmem_dev_probe()
372 ocmem->num_macros = OCMEM_HW_PROFILE_NUM_MACROS(reg); in ocmem_dev_probe()
373 ocmem->interleaved = !!(reg & OCMEM_HW_PROFILE_INTERLEAVING); in ocmem_dev_probe()
375 num_banks = ocmem->num_ports / 2; in ocmem_dev_probe()
376 region_size = ocmem->config->macro_size * num_banks; in ocmem_dev_probe()
379 ocmem->num_ports, ocmem->config->num_regions, in ocmem_dev_probe()
380 ocmem->num_macros, ocmem->interleaved ? "" : "not "); in ocmem_dev_probe()
382 ocmem->regions = devm_kcalloc(dev, ocmem->config->num_regions, in ocmem_dev_probe()
384 if (!ocmem->regions) { in ocmem_dev_probe()
389 for (i = 0; i < ocmem->config->num_regions; i++) { in ocmem_dev_probe()
390 struct ocmem_region *region = &ocmem->regions[i]; in ocmem_dev_probe()
400 if (i == (ocmem->config->num_regions - 1) && in ocmem_dev_probe()
402 region->macro_size = ocmem->config->macro_size / 2; in ocmem_dev_probe()
405 region->macro_size = ocmem->config->macro_size; in ocmem_dev_probe()
413 platform_set_drvdata(pdev, ocmem); in ocmem_dev_probe()
435 { .compatible = "qcom,msm8974-ocmem", .data = &ocmem_8974_config },
445 .name = "ocmem",
452 MODULE_DESCRIPTION("On Chip Memory (OCMEM) allocator for some Snapdragon SoCs");