summaryrefslogtreecommitdiffstats
blob: 6c5d17a0e84a25fa32743314cd1ac4ca90b99862 (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
137
138
139
140
141
142
143
144
145
146
147
/*
 * Copyright (C) 2011 Texas Instruments, Inc
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that 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/>.
 */
#include <linux/bltsville.h>
#include <linux/bvinternal.h>
#include <linux/gcbv-iface.h>

#include "gc_bvmapping.h"
#include "services_headers.h"

void gc_bvmap_meminfo(PVRSRV_KERNEL_MEM_INFO *psMemInfo)
{
	int i;
	IMG_CPU_PHYADDR phy_addr;
	unsigned long *page_addrs;
	struct bvbuffdesc *buffdesc;
	struct bvphysdesc *physdesc;
	int num_pages;
	struct bventry bv_entry;
	enum bverror bv_error;

	gcbv_init(&bv_entry);
	if (!bv_entry.bv_map) {
		psMemInfo->bvmap_handle = NULL;
		return;
	}

	num_pages = (psMemInfo->uAllocSize +
		PAGE_SIZE - 1) >> PAGE_SHIFT;

	page_addrs = kzalloc(sizeof(*page_addrs) * num_pages, GFP_KERNEL);
	if (!page_addrs) {
		printk(KERN_ERR "%s: Out of memory\n", __func__);
		return;
	}

	physdesc = kzalloc(sizeof(*physdesc), GFP_KERNEL);
	buffdesc = kzalloc(sizeof(*buffdesc), GFP_KERNEL);
	if (!buffdesc || !physdesc) {
		printk(KERN_ERR "%s: Out of memory\n", __func__);
		kfree(page_addrs);
		kfree(physdesc);
		kfree(buffdesc);
		return;
	}

	for (i = 0; i < num_pages; i++) {
		phy_addr = OSMemHandleToCpuPAddr(
			psMemInfo->sMemBlk.hOSMemHandle, i << PAGE_SHIFT);
		page_addrs[i] = (u32)phy_addr.uiAddr;
	}

	buffdesc->structsize = sizeof(*buffdesc);
	buffdesc->map = NULL;
	buffdesc->length = psMemInfo->uAllocSize;
	buffdesc->auxtype = BVAT_PHYSDESC;
	buffdesc->auxptr = physdesc;
	physdesc->structsize = sizeof(*physdesc);
	physdesc->pagesize = PAGE_SIZE;
	physdesc->pagearray = page_addrs;
	physdesc->pagecount = num_pages;

	/*
	 * For ion allocated buffers let's verify how many planes this
	 * meminfo consist of
	 */
	if(psMemInfo->ui32Flags & PVRSRV_MEM_ION) {
		IMG_UINT32 num_addr_offsets = 0;
		OSGetMemMultiPlaneInfo(psMemInfo->sMemBlk.hOSMemHandle,
			NULL, &num_addr_offsets);

		/*
		 * Account for this meminfo plane offset (relative to the base
		 * address) if necessary
		 */
		if(num_addr_offsets > 0)
			physdesc->pageoffset = psMemInfo->planeOffsets[0];

		/*
		 * In BV there is no way to specify multiple offsets, check
		 * all planes have the same offset and report any discrepancy
		 */
		for (i = 1; i < num_addr_offsets; i++) {
			IMG_UINT32 plane_offset =
				psMemInfo->planeOffsets[i] % PAGE_SIZE;
			if (psMemInfo->planeOffsets[0] != plane_offset) {
				printk(KERN_WARNING "%s: meminfo %p offset 0 %d"
					" != offset %d %d, coalignment is "
					"missing\n", __func__, psMemInfo,
					psMemInfo->planeOffsets[0],
					i, plane_offset);
			}
		}
	}

	bv_error = bv_entry.bv_map(buffdesc);
	if (bv_error) {
		printk(KERN_ERR "%s: Failed to map meminfo %p, bverror %d\n",
			__func__, psMemInfo, bv_error);
		psMemInfo->bvmap_handle = NULL;
	} else
		psMemInfo->bvmap_handle = buffdesc;

}

void gc_bvunmap_meminfo(PVRSRV_KERNEL_MEM_INFO *psMemInfo)
{
	struct bvbuffdesc *buffdesc;
	struct bvphysdesc *physdesc;
	struct bventry bv_entry;
	enum bverror bv_error;

	gcbv_init(&bv_entry);
	if (!bv_entry.bv_map || !psMemInfo || !psMemInfo->bvmap_handle)
		return;

	buffdesc = psMemInfo->bvmap_handle;
	physdesc = (struct bvphysdesc*) buffdesc->auxptr;
	bv_error = bv_entry.bv_unmap(buffdesc);
	if (bv_error) {
		printk(KERN_ERR "%s: Failed to unmap bvhandle %p from meminfo "
			"%p, bverror %d\n", __func__, buffdesc, psMemInfo,
			bv_error);
	}

	kfree(physdesc->pagearray);
	kfree(physdesc);
	kfree(psMemInfo->bvmap_handle);
	psMemInfo->bvmap_handle = NULL;
}

IMG_VOID *gc_meminfo_to_hndl(PVRSRV_KERNEL_MEM_INFO *psMemInfo)
{
	return psMemInfo->bvmap_handle;
}