Commit 26c0b26d authored by Brian Masney's avatar Brian Masney Committed by Rob Clark

drm/msm/gpu: add ocmem init/cleanup functions

The files a3xx_gpu.c and a4xx_gpu.c have ifdefs for the OCMEM support
that was missing upstream. Add two new functions (adreno_gpu_ocmem_init
and adreno_gpu_ocmem_cleanup) that removes some duplicated code.
Signed-off-by: default avatarBrian Masney <masneyb@onstation.org>
Reviewed-by: default avatarJordan Crouse <jcrouse@codeaurora.org>
Tested-by: Gabriel Francisco <frc.gabrielgmail.com>
Signed-off-by: default avatarRob Clark <robdclark@chromium.org>
parent 88c1e940
...@@ -7,6 +7,7 @@ config DRM_MSM ...@@ -7,6 +7,7 @@ config DRM_MSM
depends on OF && COMMON_CLK depends on OF && COMMON_CLK
depends on MMU depends on MMU
depends on INTERCONNECT || !INTERCONNECT depends on INTERCONNECT || !INTERCONNECT
depends on QCOM_OCMEM || QCOM_OCMEM=n
select QCOM_MDT_LOADER if ARCH_QCOM select QCOM_MDT_LOADER if ARCH_QCOM
select REGULATOR select REGULATOR
select DRM_KMS_HELPER select DRM_KMS_HELPER
......
...@@ -6,10 +6,6 @@ ...@@ -6,10 +6,6 @@
* Copyright (c) 2014 The Linux Foundation. All rights reserved. * Copyright (c) 2014 The Linux Foundation. All rights reserved.
*/ */
#ifdef CONFIG_MSM_OCMEM
# include <mach/ocmem.h>
#endif
#include "a3xx_gpu.h" #include "a3xx_gpu.h"
#define A3XX_INT0_MASK \ #define A3XX_INT0_MASK \
...@@ -195,9 +191,9 @@ static int a3xx_hw_init(struct msm_gpu *gpu) ...@@ -195,9 +191,9 @@ static int a3xx_hw_init(struct msm_gpu *gpu)
gpu_write(gpu, REG_A3XX_RBBM_GPR0_CTL, 0x00000000); gpu_write(gpu, REG_A3XX_RBBM_GPR0_CTL, 0x00000000);
/* Set the OCMEM base address for A330, etc */ /* Set the OCMEM base address for A330, etc */
if (a3xx_gpu->ocmem_hdl) { if (a3xx_gpu->ocmem.hdl) {
gpu_write(gpu, REG_A3XX_RB_GMEM_BASE_ADDR, gpu_write(gpu, REG_A3XX_RB_GMEM_BASE_ADDR,
(unsigned int)(a3xx_gpu->ocmem_base >> 14)); (unsigned int)(a3xx_gpu->ocmem.base >> 14));
} }
/* Turn on performance counters: */ /* Turn on performance counters: */
...@@ -318,10 +314,7 @@ static void a3xx_destroy(struct msm_gpu *gpu) ...@@ -318,10 +314,7 @@ static void a3xx_destroy(struct msm_gpu *gpu)
adreno_gpu_cleanup(adreno_gpu); adreno_gpu_cleanup(adreno_gpu);
#ifdef CONFIG_MSM_OCMEM adreno_gpu_ocmem_cleanup(&a3xx_gpu->ocmem);
if (a3xx_gpu->ocmem_base)
ocmem_free(OCMEM_GRAPHICS, a3xx_gpu->ocmem_hdl);
#endif
kfree(a3xx_gpu); kfree(a3xx_gpu);
} }
...@@ -494,17 +487,10 @@ struct msm_gpu *a3xx_gpu_init(struct drm_device *dev) ...@@ -494,17 +487,10 @@ struct msm_gpu *a3xx_gpu_init(struct drm_device *dev)
/* if needed, allocate gmem: */ /* if needed, allocate gmem: */
if (adreno_is_a330(adreno_gpu)) { if (adreno_is_a330(adreno_gpu)) {
#ifdef CONFIG_MSM_OCMEM ret = adreno_gpu_ocmem_init(&adreno_gpu->base.pdev->dev,
/* TODO this is different/missing upstream: */ adreno_gpu, &a3xx_gpu->ocmem);
struct ocmem_buf *ocmem_hdl = if (ret)
ocmem_allocate(OCMEM_GRAPHICS, adreno_gpu->gmem); goto fail;
a3xx_gpu->ocmem_hdl = ocmem_hdl;
a3xx_gpu->ocmem_base = ocmem_hdl->addr;
adreno_gpu->gmem = ocmem_hdl->len;
DBG("using %dK of OCMEM at 0x%08x", adreno_gpu->gmem / 1024,
a3xx_gpu->ocmem_base);
#endif
} }
if (!gpu->aspace) { if (!gpu->aspace) {
......
...@@ -19,8 +19,7 @@ struct a3xx_gpu { ...@@ -19,8 +19,7 @@ struct a3xx_gpu {
struct adreno_gpu base; struct adreno_gpu base;
/* if OCMEM is used for GMEM: */ /* if OCMEM is used for GMEM: */
uint32_t ocmem_base; struct adreno_ocmem ocmem;
void *ocmem_hdl;
}; };
#define to_a3xx_gpu(x) container_of(x, struct a3xx_gpu, base) #define to_a3xx_gpu(x) container_of(x, struct a3xx_gpu, base)
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
/* Copyright (c) 2014 The Linux Foundation. All rights reserved. /* Copyright (c) 2014 The Linux Foundation. All rights reserved.
*/ */
#include "a4xx_gpu.h" #include "a4xx_gpu.h"
#ifdef CONFIG_MSM_OCMEM
# include <soc/qcom/ocmem.h>
#endif
#define A4XX_INT0_MASK \ #define A4XX_INT0_MASK \
(A4XX_INT0_RBBM_AHB_ERROR | \ (A4XX_INT0_RBBM_AHB_ERROR | \
...@@ -188,7 +185,7 @@ static int a4xx_hw_init(struct msm_gpu *gpu) ...@@ -188,7 +185,7 @@ static int a4xx_hw_init(struct msm_gpu *gpu)
(1 << 30) | 0xFFFF); (1 << 30) | 0xFFFF);
gpu_write(gpu, REG_A4XX_RB_GMEM_BASE_ADDR, gpu_write(gpu, REG_A4XX_RB_GMEM_BASE_ADDR,
(unsigned int)(a4xx_gpu->ocmem_base >> 14)); (unsigned int)(a4xx_gpu->ocmem.base >> 14));
/* Turn on performance counters: */ /* Turn on performance counters: */
gpu_write(gpu, REG_A4XX_RBBM_PERFCTR_CTL, 0x01); gpu_write(gpu, REG_A4XX_RBBM_PERFCTR_CTL, 0x01);
...@@ -318,10 +315,7 @@ static void a4xx_destroy(struct msm_gpu *gpu) ...@@ -318,10 +315,7 @@ static void a4xx_destroy(struct msm_gpu *gpu)
adreno_gpu_cleanup(adreno_gpu); adreno_gpu_cleanup(adreno_gpu);
#ifdef CONFIG_MSM_OCMEM adreno_gpu_ocmem_cleanup(&a4xx_gpu->ocmem);
if (a4xx_gpu->ocmem_base)
ocmem_free(OCMEM_GRAPHICS, a4xx_gpu->ocmem_hdl);
#endif
kfree(a4xx_gpu); kfree(a4xx_gpu);
} }
...@@ -578,17 +572,10 @@ struct msm_gpu *a4xx_gpu_init(struct drm_device *dev) ...@@ -578,17 +572,10 @@ struct msm_gpu *a4xx_gpu_init(struct drm_device *dev)
/* if needed, allocate gmem: */ /* if needed, allocate gmem: */
if (adreno_is_a4xx(adreno_gpu)) { if (adreno_is_a4xx(adreno_gpu)) {
#ifdef CONFIG_MSM_OCMEM ret = adreno_gpu_ocmem_init(dev->dev, adreno_gpu,
/* TODO this is different/missing upstream: */ &a4xx_gpu->ocmem);
struct ocmem_buf *ocmem_hdl = if (ret)
ocmem_allocate(OCMEM_GRAPHICS, adreno_gpu->gmem); goto fail;
a4xx_gpu->ocmem_hdl = ocmem_hdl;
a4xx_gpu->ocmem_base = ocmem_hdl->addr;
adreno_gpu->gmem = ocmem_hdl->len;
DBG("using %dK of OCMEM at 0x%08x", adreno_gpu->gmem / 1024,
a4xx_gpu->ocmem_base);
#endif
} }
if (!gpu->aspace) { if (!gpu->aspace) {
......
...@@ -16,8 +16,7 @@ struct a4xx_gpu { ...@@ -16,8 +16,7 @@ struct a4xx_gpu {
struct adreno_gpu base; struct adreno_gpu base;
/* if OCMEM is used for GMEM: */ /* if OCMEM is used for GMEM: */
uint32_t ocmem_base; struct adreno_ocmem ocmem;
void *ocmem_hdl;
}; };
#define to_a4xx_gpu(x) container_of(x, struct a4xx_gpu, base) #define to_a4xx_gpu(x) container_of(x, struct a4xx_gpu, base)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/pm_opp.h> #include <linux/pm_opp.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/soc/qcom/mdt_loader.h> #include <linux/soc/qcom/mdt_loader.h>
#include <soc/qcom/ocmem.h>
#include "adreno_gpu.h" #include "adreno_gpu.h"
#include "msm_gem.h" #include "msm_gem.h"
#include "msm_mmu.h" #include "msm_mmu.h"
...@@ -893,6 +894,45 @@ static int adreno_get_pwrlevels(struct device *dev, ...@@ -893,6 +894,45 @@ static int adreno_get_pwrlevels(struct device *dev,
return 0; return 0;
} }
int adreno_gpu_ocmem_init(struct device *dev, struct adreno_gpu *adreno_gpu,
struct adreno_ocmem *adreno_ocmem)
{
struct ocmem_buf *ocmem_hdl;
struct ocmem *ocmem;
ocmem = of_get_ocmem(dev);
if (IS_ERR(ocmem)) {
if (PTR_ERR(ocmem) == -ENODEV) {
/*
* Return success since either the ocmem property was
* not specified in device tree, or ocmem support is
* not compiled into the kernel.
*/
return 0;
}
return PTR_ERR(ocmem);
}
ocmem_hdl = ocmem_allocate(ocmem, OCMEM_GRAPHICS, adreno_gpu->gmem);
if (IS_ERR(ocmem_hdl))
return PTR_ERR(ocmem_hdl);
adreno_ocmem->ocmem = ocmem;
adreno_ocmem->base = ocmem_hdl->addr;
adreno_ocmem->hdl = ocmem_hdl;
adreno_gpu->gmem = ocmem_hdl->len;
return 0;
}
void adreno_gpu_ocmem_cleanup(struct adreno_ocmem *adreno_ocmem)
{
if (adreno_ocmem && adreno_ocmem->base)
ocmem_free(adreno_ocmem->ocmem, OCMEM_GRAPHICS,
adreno_ocmem->hdl);
}
int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev, int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
struct adreno_gpu *adreno_gpu, struct adreno_gpu *adreno_gpu,
const struct adreno_gpu_funcs *funcs, int nr_rings) const struct adreno_gpu_funcs *funcs, int nr_rings)
......
...@@ -126,6 +126,12 @@ struct adreno_gpu { ...@@ -126,6 +126,12 @@ struct adreno_gpu {
}; };
#define to_adreno_gpu(x) container_of(x, struct adreno_gpu, base) #define to_adreno_gpu(x) container_of(x, struct adreno_gpu, base)
struct adreno_ocmem {
struct ocmem *ocmem;
unsigned long base;
void *hdl;
};
/* platform config data (ie. from DT, or pdata) */ /* platform config data (ie. from DT, or pdata) */
struct adreno_platform_config { struct adreno_platform_config {
struct adreno_rev rev; struct adreno_rev rev;
...@@ -236,6 +242,10 @@ void adreno_dump(struct msm_gpu *gpu); ...@@ -236,6 +242,10 @@ void adreno_dump(struct msm_gpu *gpu);
void adreno_wait_ring(struct msm_ringbuffer *ring, uint32_t ndwords); void adreno_wait_ring(struct msm_ringbuffer *ring, uint32_t ndwords);
struct msm_ringbuffer *adreno_active_ring(struct msm_gpu *gpu); struct msm_ringbuffer *adreno_active_ring(struct msm_gpu *gpu);
int adreno_gpu_ocmem_init(struct device *dev, struct adreno_gpu *adreno_gpu,
struct adreno_ocmem *ocmem);
void adreno_gpu_ocmem_cleanup(struct adreno_ocmem *ocmem);
int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev, int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
struct adreno_gpu *gpu, const struct adreno_gpu_funcs *funcs, struct adreno_gpu *gpu, const struct adreno_gpu_funcs *funcs,
int nr_rings); int nr_rings);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment