Skip to content

Commit cb3a2e3

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

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 void 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
@@ -213,13 +213,36 @@ static int isp_firmware_boot_stage1(struct apple_isp *isp)
213213
return 0;
214214
}
215215

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

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

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

261272
args_iova = isp->ipc_surf->iova + args_offset + 0x40;
@@ -296,17 +307,13 @@ static int isp_firmware_boot_stage2(struct apple_isp *isp)
296307
isp_err(isp,
297308
"never received second magic number from firmware\n");
298309
err = -ENODEV;
299-
goto free_file;
310+
goto free_extra;
300311
}
301312

302313
return 0;
303314

304-
free_file:
305-
isp_free_surface(isp, isp->data_surf);
306315
free_extra:
307316
isp_free_surface(isp, isp->extra_surf);
308-
free_ipc:
309-
isp_free_surface(isp, isp->ipc_surf);
310317
return err;
311318
}
312319

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)