Skip to content

Commit de3f018

Browse files
eilnjannau
authored andcommitted
media: apple: isp: alloc static surfaces only once
Signed-off-by: Eileen Yoon <eyn@gmx.com>
1 parent 3cecdc2 commit de3f018

3 files changed

Lines changed: 43 additions & 23 deletions

File tree

drivers/media/platform/apple/isp/isp-drv.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/workqueue.h>
2020

2121
#include "isp-cam.h"
22+
#include "isp-fw.h"
2223
#include "isp-iommu.h"
2324
#include "isp-v4l2.h"
2425

@@ -202,26 +203,34 @@ static int apple_isp_probe(struct platform_device *pdev)
202203
goto destroy_wq;
203204
}
204205

206+
err = apple_isp_alloc_firmware_surface(isp);
207+
if (err) {
208+
dev_err(dev, "failed to alloc firmware surface: %d\n", err);
209+
goto free_iommu;
210+
}
211+
205212
pm_runtime_enable(dev);
206213

207214
err = apple_isp_detect_camera(isp);
208215
if (err) {
209216
dev_err(dev, "failed to detect camera: %d\n", err);
210-
goto free_iommu;
217+
goto free_surface;
211218
}
212219

213220
err = apple_isp_setup_video(isp);
214221
if (err) {
215222
dev_err(dev, "failed to register video device: %d\n", err);
216-
goto free_iommu;
223+
goto free_surface;
217224
}
218225

219226
dev_info(dev, "apple-isp probe!\n");
220227

221228
return 0;
222229

223-
free_iommu:
230+
free_surface:
224231
pm_runtime_disable(dev);
232+
apple_isp_free_firmware_surface(isp);
233+
free_iommu:
225234
apple_isp_free_iommu(isp);
226235
destroy_wq:
227236
destroy_workqueue(isp->wq);
@@ -236,6 +245,7 @@ static int apple_isp_remove(struct platform_device *pdev)
236245

237246
apple_isp_remove_video(isp);
238247
pm_runtime_disable(isp->dev);
248+
apple_isp_free_firmware_surface(isp);
239249
apple_isp_free_iommu(isp);
240250
destroy_workqueue(isp->wq);
241251
apple_isp_detach_genpd(isp);

drivers/media/platform/apple/isp/isp-fw.c

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,36 @@ static int isp_firmware_boot_stage1(struct apple_isp *isp)
212212
return 0;
213213
}
214214

215-
static void isp_firmware_shutdown_stage2(struct apple_isp *isp)
215+
int apple_isp_alloc_firmware_surface(struct apple_isp *isp)
216+
{
217+
/* These are static, so let's do it once and for all */
218+
isp->ipc_surf = isp_alloc_surface_vmap(isp, ISP_FIRMWARE_IPC_SIZE);
219+
if (!isp->ipc_surf) {
220+
isp_err(isp, "failed to alloc shared surface for ipc\n");
221+
return -ENOMEM;
222+
}
223+
224+
isp->data_surf = isp_alloc_surface_vmap(isp, ISP_FIRMWARE_DATA_SIZE);
225+
if (!isp->data_surf) {
226+
isp_err(isp, "failed to alloc shared surface for data files\n");
227+
isp_free_surface(isp, isp->ipc_surf);
228+
return -ENOMEM;
229+
}
230+
231+
return 0;
232+
}
233+
234+
void apple_isp_free_firmware_surface(struct apple_isp *isp)
216235
{
217236
isp_free_surface(isp, isp->data_surf);
218-
isp_free_surface(isp, isp->extra_surf);
219237
isp_free_surface(isp, isp->ipc_surf);
220238
}
221239

240+
static void isp_firmware_shutdown_stage2(struct apple_isp *isp)
241+
{
242+
isp_free_surface(isp, isp->extra_surf);
243+
}
244+
222245
static int isp_firmware_boot_stage2(struct apple_isp *isp)
223246
{
224247
struct isp_firmware_bootargs args;
@@ -239,22 +262,10 @@ static int isp_firmware_boot_stage2(struct apple_isp *isp)
239262
dev_warn(isp->dev, "unexpected channel count (%d)\n",
240263
num_ipc_chans);
241264

242-
isp->ipc_surf = isp_alloc_surface_vmap(isp, ISP_FIRMWARE_IPC_SIZE);
243-
if (!isp->ipc_surf) {
244-
isp_err(isp, "failed to alloc surface for ipc\n");
245-
return -ENOMEM;
246-
}
247-
248265
isp->extra_surf = isp_alloc_surface_vmap(isp, extra_size);
249266
if (!isp->extra_surf) {
250267
isp_err(isp, "failed to alloc surface for extra heap\n");
251-
goto free_ipc;
252-
}
253-
254-
isp->data_surf = isp_alloc_surface_vmap(isp, ISP_FIRMWARE_DATA_SIZE);
255-
if (!isp->data_surf) {
256-
isp_err(isp, "failed to alloc surface for data files\n");
257-
goto free_extra;
268+
return -ENOMEM;
258269
}
259270

260271
args_iova = isp->ipc_surf->iova + args_offset + 0x40;
@@ -295,17 +306,13 @@ static int isp_firmware_boot_stage2(struct apple_isp *isp)
295306
isp_err(isp,
296307
"never received second magic number from firmware\n");
297308
err = -ENODEV;
298-
goto free_file;
309+
goto free_extra;
299310
}
300311

301312
return 0;
302313

303-
free_file:
304-
isp_free_surface(isp, isp->data_surf);
305314
free_extra:
306315
isp_free_surface(isp, isp->extra_surf);
307-
free_ipc:
308-
isp_free_surface(isp, isp->ipc_surf);
309316
return err;
310317
}
311318

drivers/media/platform/apple/isp/isp-fw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
#include "isp-drv.h"
88

9+
int apple_isp_alloc_firmware_surface(struct apple_isp *isp);
10+
void apple_isp_free_firmware_surface(struct apple_isp *isp);
11+
912
int apple_isp_firmware_boot(struct apple_isp *isp);
1013
void apple_isp_firmware_shutdown(struct apple_isp *isp);
1114

0 commit comments

Comments
 (0)