summaryrefstree
path: root/kernel/drivers/vision/dsp/dsp-core.c
blob: d8e310293eb274bf5643cb71d4c28879b341cb10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// SPDX-License-Identifier: GPL-2.0
/*
 * Samsung Exynos SoC series dsp driver
 *
 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
 *              http://www.samsung.com/
 */

#include <linux/slab.h>
#include <linux/uaccess.h>

#include "dsp-log.h"
#include "dsp-device.h"
#include "dsp-context.h"
#include "dsp-core.h"

static int dsp_open(struct inode *inode, struct file *file)
{
	int ret;
	struct miscdevice *miscdev;
	struct dsp_device *dspdev;
	struct dsp_core *core;
	struct dsp_context *dctx;

	dsp_enter();
	dsp_dbg("open start\n");
	miscdev = file->private_data;
	dspdev = dev_get_drvdata(miscdev->parent);
	core = &dspdev->core;

	ret = dsp_device_open(dspdev);
	if (ret)
		goto p_err_device;

	dctx = dsp_context_create(core);
	if (IS_ERR(dctx)) {
		ret = PTR_ERR(dctx);
		goto p_err_dctx;
	}

	file->private_data = dctx;

	dsp_info("dsp has been successfully opened\n");
	dsp_dbg("open end\n");
	dsp_leave();
	return 0;
p_err_dctx:
	dsp_device_close(core->dspdev);
p_err_device:
	return ret;
}

static int dsp_release(struct inode *inode, struct file *file)
{
	struct dsp_context *dctx;
	struct dsp_core *core;

	dsp_enter();
	dsp_dbg("release start\n");
	dctx = file->private_data;
	core = dctx->core;

	dsp_graph_manager_stop(&core->graph_manager, dctx->id);

	if (dctx->boot_count) {
		dsp_device_stop(core->dspdev, dctx->boot_count);
		dsp_graph_manager_close(&core->graph_manager, dctx->boot_count);
	}

	dsp_context_destroy(dctx);
	dsp_device_close(core->dspdev);

	dsp_info("dsp has been released\n");
	dsp_dbg("release end\n");
	dsp_leave();
	return 0;
}

static const struct file_operations dsp_file_ops = {
	.owner		= THIS_MODULE,
	.open		= dsp_open,
	.release	= dsp_release,
	.unlocked_ioctl = dsp_ioctl,
	.compat_ioctl	= dsp_compat_ioctl32,
};

/* Top-level data for debugging */
static struct dsp_miscdev *dsp_miscdev;

int dsp_core_probe(struct dsp_device *dspdev)
{
	int ret;
	struct dsp_core *core;

	dsp_enter();
	core = &dspdev->core;
	dsp_miscdev = &core->miscdev;
	core->dspdev = dspdev;

	core->ioctl_ops = dsp_context_get_ops();

	INIT_LIST_HEAD(&core->dctx_list);
	spin_lock_init(&core->dctx_slock);
	ret = dsp_util_bitmap_init(&core->context_map, "context_bitmap",
			DSP_CORE_MAX_CONTEXT);
	if (ret)
		goto p_err;

	dsp_miscdev->miscdev.minor = MISC_DYNAMIC_MINOR;
	dsp_miscdev->miscdev.name = DSP_DEV_NAME;
	dsp_miscdev->miscdev.fops = &dsp_file_ops;
	dsp_miscdev->miscdev.parent = dspdev->dev;

	ret = misc_register(&dsp_miscdev->miscdev);
	if (ret) {
		dsp_err("Failed to register miscdevice(%d)\n", ret);
		goto p_err_misc;
	}

	ret = dsp_graph_manager_probe(core);
	if (ret)
		goto p_err_graph;

	dsp_leave();
	return 0;
p_err_graph:
	misc_deregister(&dsp_miscdev->miscdev);
p_err_misc:
	dsp_util_bitmap_deinit(&core->context_map);
p_err:
	return ret;
}

void dsp_core_remove(struct dsp_core *core)
{
	dsp_enter();
	dsp_graph_manager_remove(&core->graph_manager);
	misc_deregister(&core->miscdev.miscdev);
	dsp_util_bitmap_deinit(&core->context_map);
	dsp_leave();
}