|
33 | 33 | #include "isp_v4_1_0.h"
|
34 | 34 | #include "isp_v4_1_1.h"
|
35 | 35 |
|
| 36 | +#define ISP_MC_ADDR_ALIGN (1024 * 32) |
| 37 | + |
36 | 38 | /**
|
37 | 39 | * isp_hw_init - start and test isp block
|
38 | 40 | *
|
@@ -141,6 +143,179 @@ static int isp_set_powergating_state(struct amdgpu_ip_block *ip_block,
|
141 | 143 | return 0;
|
142 | 144 | }
|
143 | 145 |
|
| 146 | +static int is_valid_isp_device(struct device *isp_parent, struct device *amdgpu_dev) |
| 147 | +{ |
| 148 | + if (isp_parent != amdgpu_dev) |
| 149 | + return -EINVAL; |
| 150 | + |
| 151 | + return 0; |
| 152 | +} |
| 153 | + |
| 154 | +/** |
| 155 | + * isp_user_buffer_alloc - create user buffer object (BO) for isp |
| 156 | + * |
| 157 | + * @dev: isp device handle |
| 158 | + * @dmabuf: DMABUF handle for isp buffer allocated in system memory |
| 159 | + * @buf_obj: GPU buffer object handle to initialize |
| 160 | + * @buf_addr: GPU addr of the pinned BO to initialize |
| 161 | + * |
| 162 | + * Imports isp DMABUF to allocate and pin a user BO for isp internal use. It does |
| 163 | + * GART alloc to generate GPU addr for BO to make it accessible through the |
| 164 | + * GART aperture for ISP HW. |
| 165 | + * |
| 166 | + * This function is exported to allow the V4L2 isp device external to drm device |
| 167 | + * to create and access the isp user BO. |
| 168 | + * |
| 169 | + * Returns: |
| 170 | + * 0 on success, negative error code otherwise. |
| 171 | + */ |
| 172 | +int isp_user_buffer_alloc(struct device *dev, void *dmabuf, |
| 173 | + void **buf_obj, u64 *buf_addr) |
| 174 | +{ |
| 175 | + struct platform_device *ispdev = to_platform_device(dev); |
| 176 | + const struct isp_platform_data *isp_pdata; |
| 177 | + struct amdgpu_device *adev; |
| 178 | + struct mfd_cell *mfd_cell; |
| 179 | + struct amdgpu_bo *bo; |
| 180 | + u64 gpu_addr; |
| 181 | + int ret; |
| 182 | + |
| 183 | + if (WARN_ON(!ispdev)) |
| 184 | + return -ENODEV; |
| 185 | + |
| 186 | + if (WARN_ON(!buf_obj)) |
| 187 | + return -EINVAL; |
| 188 | + |
| 189 | + if (WARN_ON(!buf_addr)) |
| 190 | + return -EINVAL; |
| 191 | + |
| 192 | + mfd_cell = &ispdev->mfd_cell[0]; |
| 193 | + if (!mfd_cell) |
| 194 | + return -ENODEV; |
| 195 | + |
| 196 | + isp_pdata = mfd_cell->platform_data; |
| 197 | + adev = isp_pdata->adev; |
| 198 | + |
| 199 | + ret = is_valid_isp_device(ispdev->dev.parent, adev->dev); |
| 200 | + if (ret) |
| 201 | + return ret; |
| 202 | + |
| 203 | + ret = amdgpu_bo_create_isp_user(adev, dmabuf, |
| 204 | + AMDGPU_GEM_DOMAIN_GTT, &bo, &gpu_addr); |
| 205 | + if (ret) { |
| 206 | + drm_err(&adev->ddev, "failed to alloc gart user buffer (%d)", ret); |
| 207 | + return ret; |
| 208 | + } |
| 209 | + |
| 210 | + *buf_obj = (void *)bo; |
| 211 | + *buf_addr = gpu_addr; |
| 212 | + |
| 213 | + return 0; |
| 214 | +} |
| 215 | +EXPORT_SYMBOL(isp_user_buffer_alloc); |
| 216 | + |
| 217 | +/** |
| 218 | + * isp_user_buffer_free - free isp user buffer object (BO) |
| 219 | + * |
| 220 | + * @buf_obj: amdgpu isp user BO to free |
| 221 | + * |
| 222 | + * unpin and unref BO for isp internal use. |
| 223 | + * |
| 224 | + * This function is exported to allow the V4L2 isp device |
| 225 | + * external to drm device to free the isp user BO. |
| 226 | + */ |
| 227 | +void isp_user_buffer_free(void *buf_obj) |
| 228 | +{ |
| 229 | + amdgpu_bo_free_isp_user(buf_obj); |
| 230 | +} |
| 231 | +EXPORT_SYMBOL(isp_user_buffer_free); |
| 232 | + |
| 233 | +/** |
| 234 | + * isp_kernel_buffer_alloc - create kernel buffer object (BO) for isp |
| 235 | + * |
| 236 | + * @dev: isp device handle |
| 237 | + * @size: size for the new BO |
| 238 | + * @buf_obj: GPU BO handle to initialize |
| 239 | + * @gpu_addr: GPU addr of the pinned BO |
| 240 | + * @cpu_addr: CPU address mapping of BO |
| 241 | + * |
| 242 | + * Allocates and pins a kernel BO for internal isp firmware use. |
| 243 | + * |
| 244 | + * This function is exported to allow the V4L2 isp device |
| 245 | + * external to drm device to create and access the kernel BO. |
| 246 | + * |
| 247 | + * Returns: |
| 248 | + * 0 on success, negative error code otherwise. |
| 249 | + */ |
| 250 | +int isp_kernel_buffer_alloc(struct device *dev, u64 size, |
| 251 | + void **buf_obj, u64 *gpu_addr, void **cpu_addr) |
| 252 | +{ |
| 253 | + struct platform_device *ispdev = to_platform_device(dev); |
| 254 | + struct amdgpu_bo **bo = (struct amdgpu_bo **)buf_obj; |
| 255 | + const struct isp_platform_data *isp_pdata; |
| 256 | + struct amdgpu_device *adev; |
| 257 | + struct mfd_cell *mfd_cell; |
| 258 | + int ret; |
| 259 | + |
| 260 | + if (WARN_ON(!ispdev)) |
| 261 | + return -ENODEV; |
| 262 | + |
| 263 | + if (WARN_ON(!buf_obj)) |
| 264 | + return -EINVAL; |
| 265 | + |
| 266 | + if (WARN_ON(!gpu_addr)) |
| 267 | + return -EINVAL; |
| 268 | + |
| 269 | + if (WARN_ON(!cpu_addr)) |
| 270 | + return -EINVAL; |
| 271 | + |
| 272 | + mfd_cell = &ispdev->mfd_cell[0]; |
| 273 | + if (!mfd_cell) |
| 274 | + return -ENODEV; |
| 275 | + |
| 276 | + isp_pdata = mfd_cell->platform_data; |
| 277 | + adev = isp_pdata->adev; |
| 278 | + |
| 279 | + ret = is_valid_isp_device(ispdev->dev.parent, adev->dev); |
| 280 | + if (ret) |
| 281 | + return ret; |
| 282 | + |
| 283 | + ret = amdgpu_bo_create_kernel(adev, |
| 284 | + size, |
| 285 | + ISP_MC_ADDR_ALIGN, |
| 286 | + AMDGPU_GEM_DOMAIN_GTT, |
| 287 | + bo, |
| 288 | + gpu_addr, |
| 289 | + cpu_addr); |
| 290 | + if (!cpu_addr || ret) { |
| 291 | + drm_err(&adev->ddev, "failed to alloc gart kernel buffer (%d)", ret); |
| 292 | + return ret; |
| 293 | + } |
| 294 | + |
| 295 | + return 0; |
| 296 | +} |
| 297 | +EXPORT_SYMBOL(isp_kernel_buffer_alloc); |
| 298 | + |
| 299 | +/** |
| 300 | + * isp_kernel_buffer_free - free isp kernel buffer object (BO) |
| 301 | + * |
| 302 | + * @buf_obj: amdgpu isp user BO to free |
| 303 | + * @gpu_addr: GPU addr of isp kernel BO |
| 304 | + * @cpu_addr: CPU addr of isp kernel BO |
| 305 | + * |
| 306 | + * unmaps and unpin a isp kernel BO. |
| 307 | + * |
| 308 | + * This function is exported to allow the V4L2 isp device |
| 309 | + * external to drm device to free the kernel BO. |
| 310 | + */ |
| 311 | +void isp_kernel_buffer_free(void **buf_obj, u64 *gpu_addr, void **cpu_addr) |
| 312 | +{ |
| 313 | + struct amdgpu_bo **bo = (struct amdgpu_bo **)buf_obj; |
| 314 | + |
| 315 | + amdgpu_bo_free_kernel(bo, gpu_addr, cpu_addr); |
| 316 | +} |
| 317 | +EXPORT_SYMBOL(isp_kernel_buffer_free); |
| 318 | + |
144 | 319 | static const struct amd_ip_funcs isp_ip_funcs = {
|
145 | 320 | .name = "isp_ip",
|
146 | 321 | .early_init = isp_early_init,
|
|
0 commit comments