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.
24 #include <soc/qcom/ocmem.h>
53 struct ocmem { struct
101 static inline void ocmem_write(struct ocmem *ocmem, u32 reg, u32 data) in ocmem_write() argument
103 writel(data, ocmem->mmio + reg); in ocmem_write()
106 static inline u32 ocmem_read(struct ocmem *ocmem, u32 reg) in ocmem_read() argument
108 return readl(ocmem->mmio + reg); in ocmem_read()
111 static void update_ocmem(struct ocmem *ocmem) in update_ocmem() argument
117 for (i = 0; i < ocmem->config->num_regions; i++) { in update_ocmem()
118 struct ocmem_region *region = &ocmem->regions[i]; in update_ocmem()
124 dev_dbg(ocmem->dev, "ocmem_region_mode_control %x\n", in update_ocmem()
126 ocmem_write(ocmem, OCMEM_REG_REGION_MODE_CTL, region_mode_ctrl); in update_ocmem()
129 for (i = 0; i < ocmem->config->num_regions; i++) { in update_ocmem()
130 struct ocmem_region *region = &ocmem->regions[i]; in update_ocmem()
138 ocmem_write(ocmem, OCMEM_REG_PSGSC_CTL(i), data); in update_ocmem()
142 static unsigned long phys_to_offset(struct ocmem *ocmem, in phys_to_offset() argument
145 if (addr < ocmem->memory->start || addr >= ocmem->memory->end) in phys_to_offset()
148 return addr - ocmem->memory->start; in phys_to_offset()
151 static unsigned long device_address(struct ocmem *ocmem, in device_address() argument
158 return phys_to_offset(ocmem, addr); in device_address()
161 static void update_range(struct ocmem *ocmem, struct ocmem_buf *buf, in update_range() argument
167 for (i = 0; i < ocmem->config->num_regions; i++) { in update_range()
168 struct ocmem_region *region = &ocmem->regions[i]; in update_range()
182 update_ocmem(ocmem); in update_range()
185 struct ocmem *of_get_ocmem(struct device *dev) in of_get_ocmem()
189 struct ocmem *ocmem; in of_get_ocmem() local
206 ocmem = platform_get_drvdata(pdev); in of_get_ocmem()
207 if (!ocmem) { in of_get_ocmem()
208 dev_err(dev, "Cannot get ocmem\n"); in of_get_ocmem()
212 return ocmem; in of_get_ocmem()
216 struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client, in ocmem_allocate() argument
229 if (test_and_set_bit_lock(BIT(client), &ocmem->active_allocations)) in ocmem_allocate()
239 buf->addr = device_address(ocmem, client, buf->offset); in ocmem_allocate()
242 update_range(ocmem, buf, CORE_ON, WIDE_MODE); in ocmem_allocate()
248 dev_err(ocmem->dev, "could not lock: %d\n", ret); in ocmem_allocate()
253 ocmem_write(ocmem, OCMEM_REG_GFX_MPU_START, buf->offset); in ocmem_allocate()
254 ocmem_write(ocmem, OCMEM_REG_GFX_MPU_END, in ocmem_allocate()
258 dev_dbg(ocmem->dev, "using %ldK of OCMEM at 0x%08lx for client %d\n", in ocmem_allocate()
266 clear_bit_unlock(BIT(client), &ocmem->active_allocations); in ocmem_allocate()
272 void ocmem_free(struct ocmem *ocmem, enum ocmem_client client, in ocmem_free() argument
279 update_range(ocmem, buf, CLK_OFF, MODE_DEFAULT); in ocmem_free()
287 dev_err(ocmem->dev, "could not unlock: %d\n", ret); in ocmem_free()
289 ocmem_write(ocmem, OCMEM_REG_GFX_MPU_START, 0x0); in ocmem_free()
290 ocmem_write(ocmem, OCMEM_REG_GFX_MPU_END, 0x0); in ocmem_free()
295 clear_bit_unlock(BIT(client), &ocmem->active_allocations); in ocmem_free()
304 struct ocmem *ocmem; in ocmem_dev_probe() local
309 ocmem = devm_kzalloc(dev, sizeof(*ocmem), GFP_KERNEL); in ocmem_dev_probe()
310 if (!ocmem) in ocmem_dev_probe()
313 ocmem->dev = dev; in ocmem_dev_probe()
314 ocmem->config = device_get_match_data(dev); in ocmem_dev_probe()
316 ocmem->core_clk = devm_clk_get(dev, "core"); in ocmem_dev_probe()
317 if (IS_ERR(ocmem->core_clk)) in ocmem_dev_probe()
318 return dev_err_probe(dev, PTR_ERR(ocmem->core_clk), in ocmem_dev_probe()
321 ocmem->iface_clk = devm_clk_get_optional(dev, "iface"); in ocmem_dev_probe()
322 if (IS_ERR(ocmem->iface_clk)) in ocmem_dev_probe()
323 return dev_err_probe(dev, PTR_ERR(ocmem->iface_clk), in ocmem_dev_probe()
326 ocmem->mmio = devm_platform_ioremap_resource_byname(pdev, "ctrl"); in ocmem_dev_probe()
327 if (IS_ERR(ocmem->mmio)) in ocmem_dev_probe()
328 return dev_err_probe(&pdev->dev, PTR_ERR(ocmem->mmio), in ocmem_dev_probe()
331 ocmem->memory = platform_get_resource_byname(pdev, IORESOURCE_MEM, in ocmem_dev_probe()
333 if (!ocmem->memory) { in ocmem_dev_probe()
339 WARN_ON(clk_set_rate(ocmem->core_clk, 1000) < 0); in ocmem_dev_probe()
341 ret = clk_prepare_enable(ocmem->core_clk); in ocmem_dev_probe()
343 return dev_err_probe(ocmem->dev, ret, "Failed to enable core clock\n"); in ocmem_dev_probe()
345 ret = clk_prepare_enable(ocmem->iface_clk); in ocmem_dev_probe()
347 clk_disable_unprepare(ocmem->core_clk); in ocmem_dev_probe()
348 return dev_err_probe(ocmem->dev, ret, "Failed to enable iface clock\n"); in ocmem_dev_probe()
360 reg = ocmem_read(ocmem, OCMEM_REG_HW_VERSION); in ocmem_dev_probe()
361 dev_dbg(dev, "OCMEM hardware version: %lu.%lu.%lu\n", in ocmem_dev_probe()
366 reg = ocmem_read(ocmem, OCMEM_REG_HW_PROFILE); in ocmem_dev_probe()
367 ocmem->num_ports = OCMEM_HW_PROFILE_NUM_PORTS(reg); in ocmem_dev_probe()
368 ocmem->num_macros = OCMEM_HW_PROFILE_NUM_MACROS(reg); in ocmem_dev_probe()
369 ocmem->interleaved = !!(reg & OCMEM_HW_PROFILE_INTERLEAVING); in ocmem_dev_probe()
371 num_banks = ocmem->num_ports / 2; in ocmem_dev_probe()
372 region_size = ocmem->config->macro_size * num_banks; in ocmem_dev_probe()
375 ocmem->num_ports, ocmem->config->num_regions, in ocmem_dev_probe()
376 ocmem->num_macros, ocmem->interleaved ? "" : "not "); in ocmem_dev_probe()
378 ocmem->regions = devm_kcalloc(dev, ocmem->config->num_regions, in ocmem_dev_probe()
380 if (!ocmem->regions) { in ocmem_dev_probe()
385 for (i = 0; i < ocmem->config->num_regions; i++) { in ocmem_dev_probe()
386 struct ocmem_region *region = &ocmem->regions[i]; in ocmem_dev_probe()
396 if (i == (ocmem->config->num_regions - 1) && in ocmem_dev_probe()
398 region->macro_size = ocmem->config->macro_size / 2; in ocmem_dev_probe()
401 region->macro_size = ocmem->config->macro_size; in ocmem_dev_probe()
409 platform_set_drvdata(pdev, ocmem); in ocmem_dev_probe()
414 clk_disable_unprepare(ocmem->core_clk); in ocmem_dev_probe()
415 clk_disable_unprepare(ocmem->iface_clk); in ocmem_dev_probe()
421 struct ocmem *ocmem = platform_get_drvdata(pdev); in ocmem_dev_remove() local
423 clk_disable_unprepare(ocmem->core_clk); in ocmem_dev_remove()
424 clk_disable_unprepare(ocmem->iface_clk); in ocmem_dev_remove()
440 { .compatible = "qcom,msm8226-ocmem", .data = &ocmem_8226_config },
441 { .compatible = "qcom,msm8974-ocmem", .data = &ocmem_8974_config },
451 .name = "ocmem",
458 MODULE_DESCRIPTION("On Chip Memory (OCMEM) allocator for some Snapdragon SoCs");