summaryrefslogtreecommitdiff
path: root/drivers/media/video/tiler/tcm/tcm_utils.c
blob: d47d43156ce5e397ab4ab0e2edab71738a921e4c (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <linux/init.h>
#include <linux/module.h>

#include "tcm_utils.h"
#include "tcm_dbg.h"

/*
* Assignment Utility Function
*/
void assign(IN struct tcm_area *a, IN u16 x0, IN u16 y0, IN u16 x1, IN u16 y1)
{
	a->p0.x = x0;
	a->p0.y = y0;
	a->p1.x = x1;
	a->p1.y = y1;

}

void dump_area(struct tcm_area *area)
{
	printk(KERN_NOTICE "(%d %d) - (%d %d)\n", area->p0.x,
		area->p0.y, area->p1.x, area->p1.y);
}


/*
 *      Inserts a given area at the end of a given list
 */
s32 insert_element(INOUT struct area_spec_list **list,
				IN struct tcm_area *newArea, IN u16 area_type)
{
	struct area_spec_list *list_iter = *list;
	struct area_spec_list *new_elem = NULL;
	if (list_iter == NULL) {
		list_iter = kmalloc(sizeof(struct area_spec_list), GFP_KERNEL);
		/* P("Created new List: 0x%x\n",list_iter); */
		assign(&list_iter->area, newArea->p0.x, newArea->p0.y,
						newArea->p1.x, newArea->p1.y);
		list_iter->area_type = area_type;
		list_iter->next = NULL;
		*list = list_iter;
		return TilerErrorNone;
	}

	/* move till you find the last element */
	while (list_iter->next != NULL)
		list_iter = list_iter->next;

	/* now we are the last one */
	/* P("Adding to the end of list\n"); */
	/*To Do: Check for malloc failures */
	new_elem = kmalloc(sizeof(struct area_spec_list), GFP_KERNEL);
	assign(&new_elem->area, newArea->p0.x, newArea->p0.y, newArea->p1.x,
								newArea->p1.y);
	new_elem->area_type = area_type;
	new_elem->next = NULL;
	list_iter->next = new_elem;
	return TilerErrorNone;
}

s32 rem_element_with_match(struct area_spec_list **listHead,
			struct tcm_area *to_be_removed, u16 *area_type)
{
	struct area_spec_list *temp_list = NULL;
	struct area_spec_list *matched_elem = NULL;
	struct tcm_area *cur_area = NULL;
	u8 found_flag = NO;

	/*If the area to be removed matchs the list head itself,
	we need to put the next one as list head */
	if (*listHead !=  NULL) {
		cur_area = &(*listHead)->area;
		if (cur_area->p0.x == to_be_removed->p0.x && cur_area->p0.y ==
			to_be_removed->p0.y && cur_area->p1.x ==
			to_be_removed->p1.x && cur_area->p1.y ==
			to_be_removed->p1.y) {
			*area_type = (*listHead)->area_type;
			P1("Match found, Now Removing Area : %s\n",
				AREA_STR(a_str, cur_area));

			temp_list = (*listHead)->next;
			kfree(*listHead);
			*listHead = temp_list;
			return TilerErrorNone;
		}
	}

	temp_list = *listHead;
	while (temp_list  !=  NULL) {
		/* we have already checked the list head,
			we check for the second in list */
		if (temp_list->next != NULL) {
			cur_area = &temp_list->next->area;
			if (cur_area->p0.x == to_be_removed->p0.x
				&& cur_area->p0.y == to_be_removed->p0.y
				&& cur_area->p1.x == to_be_removed->p1.x
				&& cur_area->p1.y == to_be_removed->p1.y) {
				P1("Match found, Now Removing Area : %s\n",
					AREA_STR(a_str, cur_area));
				matched_elem = temp_list->next;
				*area_type = matched_elem->area_type;
				temp_list->next = matched_elem->next;
				kfree(matched_elem);
				matched_elem = NULL;
				found_flag = YES;
				break;
			}
		}
		temp_list = temp_list->next;
	}

	if (found_flag)
		return TilerErrorNone;

	PE("Match Not found :%s\n", AREA_STR(a_str, to_be_removed));

	return TilerErrorMatchNotFound;
}

s32 clean_list(struct area_spec_list **list)
{
	struct area_spec_list *temp_list = NULL;
	struct area_spec_list *to_be_rem_elem = NULL;

	if (*list != NULL) {
		temp_list = (*list)->next;
		while (temp_list != NULL) {
			/*P("Freeing :");
			dump_area(&temp_list->area);*/
			to_be_rem_elem = temp_list->next;
			kfree(temp_list);
			temp_list = to_be_rem_elem;
		}

		/* freeing the head now */
		kfree(*list);
		*list = NULL;
	}

	return TilerErrorNone;
}

s32 dump_list_entries(IN struct area_spec_list *list)
{
	struct area_spec_list *list_iter = NULL;
	char a_str[32] = {'\0'};
	P("Printing List Entries:\n");

	if (list == NULL) {
		PE("NULL List found\n");
		return TilerErrorInvalidArg;
	}

	/*Now if we have a valid list, let us print the values */
	list_iter = list;
	do {
		printk(KERN_NOTICE "%dD:%s\n", list_iter->area_type,
					AREA_STR(a_str, &list_iter->area));
		/* dump_area(&list_iter->area); */
		list_iter = list_iter->next;
	} while (list_iter != NULL);

	return TilerErrorNone;
}



s32 dump_neigh_stats(struct neighbour_stats *neighbour)
{
	P("Top  Occ:Boundary  %d:%d\n", neighbour->top_occupied,
						neighbour->top_boundary);
	P("Bot  Occ:Boundary  %d:%d\n", neighbour->bottom_occupied,
						neighbour->bottom_boundary);
	P("Left Occ:Boundary  %d:%d\n", neighbour->left_occupied,
						neighbour->left_boundary);
	P("Rigt Occ:Boundary  %d:%d\n", neighbour->right_occupied,
						neighbour->right_boundary);
	return TilerErrorNone;
}