summaryrefslogtreecommitdiffstats
path: root/drivers/video/tegra/host/dev.c
blob: 56af47a48ce5cc01c1208ea89b000c01636958c8 (plain) (blame)
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
/*
 * drivers/video/tegra/host/dev.c
 *
 * Tegra Graphics Host Driver Entrypoint
 *
 * Copyright (c) 2010-2014, NVIDIA Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#define CREATE_TRACE_POINTS
#include <trace/events/nvhost.h>

#include <linux/module.h>
#include <linux/io.h>
#include <linux/nvhost.h>
#include <linux/list.h>
#include <linux/slab.h>

#include <mach/gpufuse.h>

#include "dev.h"

#if defined(NVHOST_DEBUG)
u32 nvhost_dbg_mask = NVHOST_DEFAULT_DBG_MASK;
u32 nvhost_dbg_ftrace;
#endif

/* host1x device list is used in 2 places:
 * 1. In ioctl(NVHOST_IOCTL_CTRL_MODULE_REGRDWR) of host1x device
 * 2. debug-fs dump of host1x and client device
 *    as well as channel state */
struct nvhost_device_list {
	struct list_head list;
	struct platform_device *pdev;
};

/* HEAD for the host1x device list */
static struct nvhost_device_list ndev_head;

/* Constructor for the host1x device list */
void nvhost_device_list_init(void)
{
	INIT_LIST_HEAD(&ndev_head.list);
}

/* Adds a device to tail of host1x device list */
int nvhost_device_list_add(struct platform_device *pdev)
{
	struct nvhost_device_list *list;

	list = kzalloc(sizeof(struct nvhost_device_list), GFP_KERNEL);
	if (!list)
		return -ENOMEM;

	list->pdev = pdev;
	list_add_tail(&list->list, &ndev_head.list);

	return 0;
}

/* Iterator function for host1x device list
 * It takes a fptr as an argument and calls that function for each
 * device in the list */
void nvhost_device_list_for_all(void *data,
	int (*fptr)(struct platform_device *pdev, void *fdata, int locked_id),
	int locked_id)
{
	struct list_head *pos;
	struct nvhost_device_list *nlist;
	int ret;

	list_for_each(pos, &ndev_head.list) {
		nlist = list_entry(pos, struct nvhost_device_list, list);
		if (nlist && nlist->pdev && fptr) {
			ret = fptr(nlist->pdev, data, locked_id);
			if (ret) {
				pr_info("%s: iterator error\n", __func__);
				break;
			}
		}
	}
}

/* Simple search function for the host1x device list
 * It takes the moduleid as argument and returns a pointer to host1x
 * device that matches the moduleid otherwise returns NULL */
struct platform_device *nvhost_device_list_match_by_id(u32 id)
{
	struct list_head *pos;
	struct nvhost_device_list *nlist;
	struct nvhost_device_data *pdata;

	list_for_each(pos, &ndev_head.list) {
		nlist = list_entry(pos, struct nvhost_device_list, list);
		if (nlist && nlist->pdev) {
			pdata = platform_get_drvdata(nlist->pdev);
			if (pdata && (pdata->moduleid == id))
				return nlist->pdev;
		}
	}

	return NULL;
}

/* Removes a device from the host1x device list */
void nvhost_device_list_remove(struct platform_device *pdev)
{
	struct list_head *pos;
	struct nvhost_device_list *nlist;

	list_for_each(pos, &ndev_head.list) {
		nlist = list_entry(pos, struct nvhost_device_list, list);
		if (nlist && nlist->pdev == pdev) {
			list_del(&nlist->list);
			kfree(nlist);
			break;
		}
	}
}

MODULE_AUTHOR("NVIDIA");
MODULE_DESCRIPTION("Graphics host driver for Tegra products");
MODULE_VERSION("1.0");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform-nvhost");