1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
6 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
9 #include <linux/ascii85.h>
10 #include <linux/interconnect.h>
11 #include <linux/qcom_scm.h>
12 #include <linux/kernel.h>
13 #include <linux/of_address.h>
14 #include <linux/pm_opp.h>
15 #include <linux/slab.h>
16 #include <linux/soc/qcom/mdt_loader.h>
17 #include <soc/qcom/ocmem.h>
18 #include "adreno_gpu.h"
23 static bool zap_available = true;
25 static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname,
28 struct device *dev = &gpu->pdev->dev;
29 const struct firmware *fw;
30 const char *signed_fwname = NULL;
31 struct device_node *np, *mem_np;
35 void *mem_region = NULL;
38 if (!IS_ENABLED(CONFIG_ARCH_QCOM)) {
39 zap_available = false;
43 np = of_get_child_by_name(dev->of_node, "zap-shader");
45 zap_available = false;
49 mem_np = of_parse_phandle(np, "memory-region", 0);
52 zap_available = false;
56 ret = of_address_to_resource(mem_np, 0, &r);
64 * Check for a firmware-name property. This is the new scheme
65 * to handle firmware that may be signed with device specific
66 * keys, allowing us to have a different zap fw path for different
69 * If the firmware-name property is found, we bypass the
70 * adreno_request_fw() mechanism, because we don't need to handle
71 * the /lib/firmware/qcom/... vs /lib/firmware/... case.
73 * If the firmware-name property is not found, for backwards
74 * compatibility we fall back to the fwname from the gpulist
77 of_property_read_string_index(np, "firmware-name", 0, &signed_fwname);
79 fwname = signed_fwname;
80 ret = request_firmware_direct(&fw, fwname, gpu->dev->dev);
84 /* Request the MDT file from the default location: */
85 fw = adreno_request_fw(to_adreno_gpu(gpu), fwname);
88 * For new targets, we require the firmware-name property,
89 * if a zap-shader is required, rather than falling back
90 * to a firmware name specified in gpulist.
92 * Because the firmware is signed with a (potentially)
93 * device specific key, having the name come from gpulist
94 * was a bad idea, and is only provided for backwards
95 * compatibility for older targets.
101 DRM_DEV_ERROR(dev, "Unable to load %s\n", fwname);
105 /* Figure out how much memory we need */
106 mem_size = qcom_mdt_get_size(fw);
112 if (mem_size > resource_size(&r)) {
114 "memory region is too small to load the MDT\n");
119 /* Allocate memory for the firmware image */
120 mem_region = memremap(mem_phys, mem_size, MEMREMAP_WC);
127 * Load the rest of the MDT
129 * Note that we could be dealing with two different paths, since
130 * with upstream linux-firmware it would be in a qcom/ subdir..
131 * adreno_request_fw() handles this, but qcom_mdt_load() does
132 * not. But since we've already gotten through adreno_request_fw()
133 * we know which of the two cases it is:
135 if (signed_fwname || (to_adreno_gpu(gpu)->fwloc == FW_LOCATION_LEGACY)) {
136 ret = qcom_mdt_load(dev, fw, fwname, pasid,
137 mem_region, mem_phys, mem_size, NULL);
141 newname = kasprintf(GFP_KERNEL, "qcom/%s", fwname);
143 ret = qcom_mdt_load(dev, fw, newname, pasid,
144 mem_region, mem_phys, mem_size, NULL);
150 /* Send the image to the secure world */
151 ret = qcom_scm_pas_auth_and_reset(pasid);
154 * If the scm call returns -EOPNOTSUPP we assume that this target
155 * doesn't need/support the zap shader so quietly fail
157 if (ret == -EOPNOTSUPP)
158 zap_available = false;
160 DRM_DEV_ERROR(dev, "Unable to authorize the image\n");
164 memunmap(mem_region);
166 release_firmware(fw);
171 int adreno_zap_shader_load(struct msm_gpu *gpu, u32 pasid)
173 struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
174 struct platform_device *pdev = gpu->pdev;
176 /* Short cut if we determine the zap shader isn't available/needed */
180 /* We need SCM to be able to load the firmware */
181 if (!qcom_scm_is_available()) {
182 DRM_DEV_ERROR(&pdev->dev, "SCM is not available\n");
183 return -EPROBE_DEFER;
186 return zap_shader_load_mdt(gpu, adreno_gpu->info->zapfw, pasid);
189 struct msm_gem_address_space *
190 adreno_iommu_create_address_space(struct msm_gpu *gpu,
191 struct platform_device *pdev)
193 struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
194 struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
195 struct io_pgtable_domain_attr pgtbl_cfg;
196 struct iommu_domain *iommu;
198 struct msm_gem_address_space *aspace;
201 iommu = iommu_domain_alloc(&platform_bus_type);
206 * This allows GPU to set the bus attributes required to use system
207 * cache on behalf of the iommu page table walker.
209 if (!IS_ERR(a6xx_gpu->htw_llc_slice)) {
210 pgtbl_cfg.quirks = IO_PGTABLE_QUIRK_ARM_OUTER_WBWA;
211 iommu_domain_set_attr(iommu, DOMAIN_ATTR_IO_PGTABLE_CFG, &pgtbl_cfg);
214 mmu = msm_iommu_new(&pdev->dev, iommu);
216 iommu_domain_free(iommu);
217 return ERR_CAST(mmu);
221 * Use the aperture start or SZ_16M, whichever is greater. This will
222 * ensure that we align with the allocated pagetable range while still
223 * allowing room in the lower 32 bits for GMEM and whatnot
225 start = max_t(u64, SZ_16M, iommu->geometry.aperture_start);
226 size = iommu->geometry.aperture_end - start + 1;
228 aspace = msm_gem_address_space_create(mmu, "gpu",
229 start & GENMASK_ULL(48, 0), size);
231 if (IS_ERR(aspace) && !IS_ERR(mmu))
232 mmu->funcs->destroy(mmu);
237 int adreno_get_param(struct msm_gpu *gpu, uint32_t param, uint64_t *value)
239 struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
242 case MSM_PARAM_GPU_ID:
243 *value = adreno_gpu->info->revn;
245 case MSM_PARAM_GMEM_SIZE:
246 *value = adreno_gpu->gmem;
248 case MSM_PARAM_GMEM_BASE:
249 *value = !adreno_is_a650(adreno_gpu) ? 0x100000 : 0;
251 case MSM_PARAM_CHIP_ID:
252 *value = adreno_gpu->rev.patchid |
253 (adreno_gpu->rev.minor << 8) |
254 (adreno_gpu->rev.major << 16) |
255 (adreno_gpu->rev.core << 24);
257 case MSM_PARAM_MAX_FREQ:
258 *value = adreno_gpu->base.fast_rate;
260 case MSM_PARAM_TIMESTAMP:
261 if (adreno_gpu->funcs->get_timestamp) {
264 pm_runtime_get_sync(&gpu->pdev->dev);
265 ret = adreno_gpu->funcs->get_timestamp(gpu, value);
266 pm_runtime_put_autosuspend(&gpu->pdev->dev);
271 case MSM_PARAM_NR_RINGS:
272 *value = gpu->nr_rings;
274 case MSM_PARAM_PP_PGTABLE:
277 case MSM_PARAM_FAULTS:
278 *value = gpu->global_faults;
281 DBG("%s: invalid param: %u", gpu->name, param);
286 const struct firmware *
287 adreno_request_fw(struct adreno_gpu *adreno_gpu, const char *fwname)
289 struct drm_device *drm = adreno_gpu->base.dev;
290 const struct firmware *fw = NULL;
294 newname = kasprintf(GFP_KERNEL, "qcom/%s", fwname);
296 return ERR_PTR(-ENOMEM);
299 * Try first to load from qcom/$fwfile using a direct load (to avoid
300 * a potential timeout waiting for usermode helper)
302 if ((adreno_gpu->fwloc == FW_LOCATION_UNKNOWN) ||
303 (adreno_gpu->fwloc == FW_LOCATION_NEW)) {
305 ret = request_firmware_direct(&fw, newname, drm->dev);
307 DRM_DEV_INFO(drm->dev, "loaded %s from new location\n",
309 adreno_gpu->fwloc = FW_LOCATION_NEW;
311 } else if (adreno_gpu->fwloc != FW_LOCATION_UNKNOWN) {
312 DRM_DEV_ERROR(drm->dev, "failed to load %s: %d\n",
320 * Then try the legacy location without qcom/ prefix
322 if ((adreno_gpu->fwloc == FW_LOCATION_UNKNOWN) ||
323 (adreno_gpu->fwloc == FW_LOCATION_LEGACY)) {
325 ret = request_firmware_direct(&fw, fwname, drm->dev);
327 DRM_DEV_INFO(drm->dev, "loaded %s from legacy location\n",
329 adreno_gpu->fwloc = FW_LOCATION_LEGACY;
331 } else if (adreno_gpu->fwloc != FW_LOCATION_UNKNOWN) {
332 DRM_DEV_ERROR(drm->dev, "failed to load %s: %d\n",
340 * Finally fall back to request_firmware() for cases where the
341 * usermode helper is needed (I think mainly android)
343 if ((adreno_gpu->fwloc == FW_LOCATION_UNKNOWN) ||
344 (adreno_gpu->fwloc == FW_LOCATION_HELPER)) {
346 ret = request_firmware(&fw, newname, drm->dev);
348 DRM_DEV_INFO(drm->dev, "loaded %s with helper\n",
350 adreno_gpu->fwloc = FW_LOCATION_HELPER;
352 } else if (adreno_gpu->fwloc != FW_LOCATION_UNKNOWN) {
353 DRM_DEV_ERROR(drm->dev, "failed to load %s: %d\n",
360 DRM_DEV_ERROR(drm->dev, "failed to load %s\n", fwname);
361 fw = ERR_PTR(-ENOENT);
367 int adreno_load_fw(struct adreno_gpu *adreno_gpu)
371 for (i = 0; i < ARRAY_SIZE(adreno_gpu->info->fw); i++) {
372 const struct firmware *fw;
374 if (!adreno_gpu->info->fw[i])
377 /* Skip if the firmware has already been loaded */
378 if (adreno_gpu->fw[i])
381 fw = adreno_request_fw(adreno_gpu, adreno_gpu->info->fw[i]);
385 adreno_gpu->fw[i] = fw;
391 struct drm_gem_object *adreno_fw_create_bo(struct msm_gpu *gpu,
392 const struct firmware *fw, u64 *iova)
394 struct drm_gem_object *bo;
397 ptr = msm_gem_kernel_new_locked(gpu->dev, fw->size - 4,
398 MSM_BO_UNCACHED | MSM_BO_GPU_READONLY, gpu->aspace, &bo, iova);
401 return ERR_CAST(ptr);
403 memcpy(ptr, &fw->data[4], fw->size - 4);
405 msm_gem_put_vaddr(bo);
410 int adreno_hw_init(struct msm_gpu *gpu)
412 struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
415 DBG("%s", gpu->name);
417 ret = adreno_load_fw(adreno_gpu);
421 for (i = 0; i < gpu->nr_rings; i++) {
422 struct msm_ringbuffer *ring = gpu->rb[i];
427 ring->cur = ring->start;
428 ring->next = ring->start;
430 /* reset completed fence seqno: */
431 ring->memptrs->fence = ring->fctx->completed_fence;
432 ring->memptrs->rptr = 0;
438 /* Use this helper to read rptr, since a430 doesn't update rptr in memory */
439 static uint32_t get_rptr(struct adreno_gpu *adreno_gpu,
440 struct msm_ringbuffer *ring)
442 struct msm_gpu *gpu = &adreno_gpu->base;
444 return gpu->funcs->get_rptr(gpu, ring);
447 struct msm_ringbuffer *adreno_active_ring(struct msm_gpu *gpu)
452 void adreno_recover(struct msm_gpu *gpu)
454 struct drm_device *dev = gpu->dev;
457 // XXX pm-runtime?? we *need* the device to be off after this
458 // so maybe continuing to call ->pm_suspend/resume() is better?
460 gpu->funcs->pm_suspend(gpu);
461 gpu->funcs->pm_resume(gpu);
463 ret = msm_gpu_hw_init(gpu);
465 DRM_DEV_ERROR(dev->dev, "gpu hw init failed: %d\n", ret);
470 void adreno_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring, u32 reg)
474 /* Copy the shadow to the actual register */
475 ring->cur = ring->next;
478 * Mask wptr value that we calculate to fit in the HW range. This is
479 * to account for the possibility that the last command fit exactly into
480 * the ringbuffer and rb->next hasn't wrapped to zero yet
482 wptr = get_wptr(ring);
484 /* ensure writes to ringbuffer have hit system memory: */
487 gpu_write(gpu, reg, wptr);
490 bool adreno_idle(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
492 struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
493 uint32_t wptr = get_wptr(ring);
495 /* wait for CP to drain ringbuffer: */
496 if (!spin_until(get_rptr(adreno_gpu, ring) == wptr))
499 /* TODO maybe we need to reset GPU here to recover from hang? */
500 DRM_ERROR("%s: timeout waiting to drain ringbuffer %d rptr/wptr = %X/%X\n",
501 gpu->name, ring->id, get_rptr(adreno_gpu, ring), wptr);
506 int adreno_gpu_state_get(struct msm_gpu *gpu, struct msm_gpu_state *state)
508 struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
511 kref_init(&state->ref);
513 ktime_get_real_ts64(&state->time);
515 for (i = 0; i < gpu->nr_rings; i++) {
518 state->ring[i].fence = gpu->rb[i]->memptrs->fence;
519 state->ring[i].iova = gpu->rb[i]->iova;
520 state->ring[i].seqno = gpu->rb[i]->seqno;
521 state->ring[i].rptr = get_rptr(adreno_gpu, gpu->rb[i]);
522 state->ring[i].wptr = get_wptr(gpu->rb[i]);
524 /* Copy at least 'wptr' dwords of the data */
525 size = state->ring[i].wptr;
527 /* After wptr find the last non zero dword to save space */
528 for (j = state->ring[i].wptr; j < MSM_GPU_RINGBUFFER_SZ >> 2; j++)
529 if (gpu->rb[i]->start[j])
533 state->ring[i].data = kvmalloc(size << 2, GFP_KERNEL);
534 if (state->ring[i].data) {
535 memcpy(state->ring[i].data, gpu->rb[i]->start, size << 2);
536 state->ring[i].data_size = size << 2;
541 /* Some targets prefer to collect their own registers */
542 if (!adreno_gpu->registers)
545 /* Count the number of registers */
546 for (i = 0; adreno_gpu->registers[i] != ~0; i += 2)
547 count += adreno_gpu->registers[i + 1] -
548 adreno_gpu->registers[i] + 1;
550 state->registers = kcalloc(count * 2, sizeof(u32), GFP_KERNEL);
551 if (state->registers) {
554 for (i = 0; adreno_gpu->registers[i] != ~0; i += 2) {
555 u32 start = adreno_gpu->registers[i];
556 u32 end = adreno_gpu->registers[i + 1];
559 for (addr = start; addr <= end; addr++) {
560 state->registers[pos++] = addr;
561 state->registers[pos++] = gpu_read(gpu, addr);
565 state->nr_registers = count;
571 void adreno_gpu_state_destroy(struct msm_gpu_state *state)
575 for (i = 0; i < ARRAY_SIZE(state->ring); i++)
576 kvfree(state->ring[i].data);
578 for (i = 0; state->bos && i < state->nr_bos; i++)
579 kvfree(state->bos[i].data);
584 kfree(state->registers);
587 static void adreno_gpu_state_kref_destroy(struct kref *kref)
589 struct msm_gpu_state *state = container_of(kref,
590 struct msm_gpu_state, ref);
592 adreno_gpu_state_destroy(state);
596 int adreno_gpu_state_put(struct msm_gpu_state *state)
598 if (IS_ERR_OR_NULL(state))
601 return kref_put(&state->ref, adreno_gpu_state_kref_destroy);
604 #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
606 static char *adreno_gpu_ascii85_encode(u32 *src, size_t len)
609 size_t buf_itr = 0, buffer_size;
610 char out[ASCII85_BUFSZ];
617 l = ascii85_encode_len(len);
620 * Ascii85 outputs either a 5 byte string or a 1 byte string. So we
621 * account for the worst case of 5 bytes per dword plus the 1 for '\0'
623 buffer_size = (l * 5) + 1;
625 buf = kvmalloc(buffer_size, GFP_KERNEL);
629 for (i = 0; i < l; i++)
630 buf_itr += scnprintf(buf + buf_itr, buffer_size - buf_itr, "%s",
631 ascii85_encode(src[i], out));
636 /* len is expected to be in bytes */
637 static void adreno_show_object(struct drm_printer *p, void **ptr, int len,
648 * Only dump the non-zero part of the buffer - rarely will
649 * any data completely fill the entire allocated size of
652 for (datalen = 0, i = 0; i < len >> 2; i++)
654 datalen = ((i + 1) << 2);
657 * If we reach here, then the originally captured binary buffer
658 * will be replaced with the ascii85 encoded string
660 *ptr = adreno_gpu_ascii85_encode(buf, datalen);
670 drm_puts(p, " data: !!ascii85 |\n");
678 void adreno_show(struct msm_gpu *gpu, struct msm_gpu_state *state,
679 struct drm_printer *p)
681 struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
684 if (IS_ERR_OR_NULL(state))
687 drm_printf(p, "revision: %d (%d.%d.%d.%d)\n",
688 adreno_gpu->info->revn, adreno_gpu->rev.core,
689 adreno_gpu->rev.major, adreno_gpu->rev.minor,
690 adreno_gpu->rev.patchid);
692 drm_printf(p, "rbbm-status: 0x%08x\n", state->rbbm_status);
694 drm_puts(p, "ringbuffer:\n");
696 for (i = 0; i < gpu->nr_rings; i++) {
697 drm_printf(p, " - id: %d\n", i);
698 drm_printf(p, " iova: 0x%016llx\n", state->ring[i].iova);
699 drm_printf(p, " last-fence: %d\n", state->ring[i].seqno);
700 drm_printf(p, " retired-fence: %d\n", state->ring[i].fence);
701 drm_printf(p, " rptr: %d\n", state->ring[i].rptr);
702 drm_printf(p, " wptr: %d\n", state->ring[i].wptr);
703 drm_printf(p, " size: %d\n", MSM_GPU_RINGBUFFER_SZ);
705 adreno_show_object(p, &state->ring[i].data,
706 state->ring[i].data_size, &state->ring[i].encoded);
710 drm_puts(p, "bos:\n");
712 for (i = 0; i < state->nr_bos; i++) {
713 drm_printf(p, " - iova: 0x%016llx\n",
715 drm_printf(p, " size: %zd\n", state->bos[i].size);
717 adreno_show_object(p, &state->bos[i].data,
718 state->bos[i].size, &state->bos[i].encoded);
722 if (state->nr_registers) {
723 drm_puts(p, "registers:\n");
725 for (i = 0; i < state->nr_registers; i++) {
726 drm_printf(p, " - { offset: 0x%04x, value: 0x%08x }\n",
727 state->registers[i * 2] << 2,
728 state->registers[(i * 2) + 1]);
734 /* Dump common gpu status and scratch registers on any hang, to make
735 * the hangcheck logs more useful. The scratch registers seem always
736 * safe to read when GPU has hung (unlike some other regs, depending
737 * on how the GPU hung), and they are useful to match up to cmdstream
738 * dumps when debugging hangs:
740 void adreno_dump_info(struct msm_gpu *gpu)
742 struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
745 printk("revision: %d (%d.%d.%d.%d)\n",
746 adreno_gpu->info->revn, adreno_gpu->rev.core,
747 adreno_gpu->rev.major, adreno_gpu->rev.minor,
748 adreno_gpu->rev.patchid);
750 for (i = 0; i < gpu->nr_rings; i++) {
751 struct msm_ringbuffer *ring = gpu->rb[i];
753 printk("rb %d: fence: %d/%d\n", i,
754 ring->memptrs->fence,
757 printk("rptr: %d\n", get_rptr(adreno_gpu, ring));
758 printk("rb wptr: %d\n", get_wptr(ring));
762 /* would be nice to not have to duplicate the _show() stuff with printk(): */
763 void adreno_dump(struct msm_gpu *gpu)
765 struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
768 if (!adreno_gpu->registers)
771 /* dump these out in a form that can be parsed by demsm: */
772 printk("IO:region %s 00000000 00020000\n", gpu->name);
773 for (i = 0; adreno_gpu->registers[i] != ~0; i += 2) {
774 uint32_t start = adreno_gpu->registers[i];
775 uint32_t end = adreno_gpu->registers[i+1];
778 for (addr = start; addr <= end; addr++) {
779 uint32_t val = gpu_read(gpu, addr);
780 printk("IO:R %08x %08x\n", addr<<2, val);
785 static uint32_t ring_freewords(struct msm_ringbuffer *ring)
787 struct adreno_gpu *adreno_gpu = to_adreno_gpu(ring->gpu);
788 uint32_t size = MSM_GPU_RINGBUFFER_SZ >> 2;
789 /* Use ring->next to calculate free size */
790 uint32_t wptr = ring->next - ring->start;
791 uint32_t rptr = get_rptr(adreno_gpu, ring);
792 return (rptr + (size - 1) - wptr) % size;
795 void adreno_wait_ring(struct msm_ringbuffer *ring, uint32_t ndwords)
797 if (spin_until(ring_freewords(ring) >= ndwords))
798 DRM_DEV_ERROR(ring->gpu->dev->dev,
799 "timeout waiting for space in ringbuffer %d\n",
803 /* Get legacy powerlevels from qcom,gpu-pwrlevels and populate the opp table */
804 static int adreno_get_legacy_pwrlevels(struct device *dev)
806 struct device_node *child, *node;
809 node = of_get_compatible_child(dev->of_node, "qcom,gpu-pwrlevels");
811 DRM_DEV_DEBUG(dev, "Could not find the GPU powerlevels\n");
815 for_each_child_of_node(node, child) {
818 ret = of_property_read_u32(child, "qcom,gpu-freq", &val);
823 * Skip the intentionally bogus clock value found at the bottom
824 * of most legacy frequency tables
827 dev_pm_opp_add(dev, val, 0);
835 static void adreno_get_pwrlevels(struct device *dev,
838 unsigned long freq = ULONG_MAX;
839 struct dev_pm_opp *opp;
844 /* You down with OPP? */
845 if (!of_find_property(dev->of_node, "operating-points-v2", NULL))
846 ret = adreno_get_legacy_pwrlevels(dev);
848 ret = dev_pm_opp_of_add_table(dev);
850 DRM_DEV_ERROR(dev, "Unable to set the OPP table\n");
854 /* Find the fastest defined rate */
855 opp = dev_pm_opp_find_freq_floor(dev, &freq);
857 gpu->fast_rate = freq;
862 if (!gpu->fast_rate) {
864 "Could not find a clock rate. Using a reasonable default\n");
865 /* Pick a suitably safe clock speed for any target */
866 gpu->fast_rate = 200000000;
869 DBG("fast_rate=%u, slow_rate=27000000", gpu->fast_rate);
872 int adreno_gpu_ocmem_init(struct device *dev, struct adreno_gpu *adreno_gpu,
873 struct adreno_ocmem *adreno_ocmem)
875 struct ocmem_buf *ocmem_hdl;
878 ocmem = of_get_ocmem(dev);
880 if (PTR_ERR(ocmem) == -ENODEV) {
882 * Return success since either the ocmem property was
883 * not specified in device tree, or ocmem support is
884 * not compiled into the kernel.
889 return PTR_ERR(ocmem);
892 ocmem_hdl = ocmem_allocate(ocmem, OCMEM_GRAPHICS, adreno_gpu->gmem);
893 if (IS_ERR(ocmem_hdl))
894 return PTR_ERR(ocmem_hdl);
896 adreno_ocmem->ocmem = ocmem;
897 adreno_ocmem->base = ocmem_hdl->addr;
898 adreno_ocmem->hdl = ocmem_hdl;
899 adreno_gpu->gmem = ocmem_hdl->len;
904 void adreno_gpu_ocmem_cleanup(struct adreno_ocmem *adreno_ocmem)
906 if (adreno_ocmem && adreno_ocmem->base)
907 ocmem_free(adreno_ocmem->ocmem, OCMEM_GRAPHICS,
911 int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
912 struct adreno_gpu *adreno_gpu,
913 const struct adreno_gpu_funcs *funcs, int nr_rings)
915 struct device *dev = &pdev->dev;
916 struct adreno_platform_config *config = dev->platform_data;
917 struct msm_gpu_config adreno_gpu_config = { 0 };
918 struct msm_gpu *gpu = &adreno_gpu->base;
920 adreno_gpu->funcs = funcs;
921 adreno_gpu->info = adreno_info(config->rev);
922 adreno_gpu->gmem = adreno_gpu->info->gmem;
923 adreno_gpu->revn = adreno_gpu->info->revn;
924 adreno_gpu->rev = config->rev;
926 adreno_gpu_config.ioname = "kgsl_3d0_reg_memory";
928 adreno_gpu_config.nr_rings = nr_rings;
930 adreno_get_pwrlevels(dev, gpu);
932 pm_runtime_set_autosuspend_delay(dev,
933 adreno_gpu->info->inactive_period);
934 pm_runtime_use_autosuspend(dev);
935 pm_runtime_enable(dev);
937 return msm_gpu_init(drm, pdev, &adreno_gpu->base, &funcs->base,
938 adreno_gpu->info->name, &adreno_gpu_config);
941 void adreno_gpu_cleanup(struct adreno_gpu *adreno_gpu)
943 struct msm_gpu *gpu = &adreno_gpu->base;
944 struct msm_drm_private *priv = gpu->dev->dev_private;
947 for (i = 0; i < ARRAY_SIZE(adreno_gpu->info->fw); i++)
948 release_firmware(adreno_gpu->fw[i]);
950 pm_runtime_disable(&priv->gpu_pdev->dev);
952 msm_gpu_cleanup(&adreno_gpu->base);
954 icc_put(gpu->icc_path);
955 icc_put(gpu->ocmem_icc_path);