Subversion Repositories Kolibri OS

Rev

Rev 4075 | Rev 4111 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4075 Rev 4080
1
/**************************************************************************
1
/**************************************************************************
2
 *
2
 *
3
 * Copyright © 2009-2011 VMware, Inc., Palo Alto, CA., USA
3
 * Copyright © 2009-2011 VMware, Inc., Palo Alto, CA., USA
4
 * All Rights Reserved.
4
 * All Rights Reserved.
5
 *
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the
7
 * copy of this software and associated documentation files (the
8
 * "Software"), to deal in the Software without restriction, including
8
 * "Software"), to deal in the Software without restriction, including
9
 * without limitation the rights to use, copy, modify, merge, publish,
9
 * without limitation the rights to use, copy, modify, merge, publish,
10
 * distribute, sub license, and/or sell copies of the Software, and to
10
 * distribute, sub license, and/or sell copies of the Software, and to
11
 * permit persons to whom the Software is furnished to do so, subject to
11
 * permit persons to whom the Software is furnished to do so, subject to
12
 * the following conditions:
12
 * the following conditions:
13
 *
13
 *
14
 * The above copyright notice and this permission notice (including the
14
 * The above copyright notice and this permission notice (including the
15
 * next paragraph) shall be included in all copies or substantial portions
15
 * next paragraph) shall be included in all copies or substantial portions
16
 * of the Software.
16
 * of the Software.
17
 *
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21
 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
21
 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25
 *
25
 *
26
 **************************************************************************/
26
 **************************************************************************/
27
#define mb()    asm volatile("mfence" : : : "memory")
27
#define mb()    asm volatile("mfence" : : : "memory")
28
#define rmb()   asm volatile("lfence" : : : "memory")
28
#define rmb()   asm volatile("lfence" : : : "memory")
29
#define wmb()   asm volatile("sfence" : : : "memory")
29
#define wmb()   asm volatile("sfence" : : : "memory")
-
 
30
 
30
 
31
#include "vmwgfx_drv.h"
31
#include 
32
#include 
32
#include 
-
 
33
#include "vmwgfx_drv.h"
-
 
34
 
33
#include 
35
 
34
 
36
#define VMW_PPN_SIZE sizeof(unsigned long)
35
#define VMW_PPN_SIZE sizeof(unsigned long)
37
 
36
 
38
static int vmw_gmr2_bind(struct vmw_private *dev_priv,
37
static int vmw_gmr2_bind(struct vmw_private *dev_priv,
39
			 struct page *pages[],
38
			 struct page *pages[],
40
			 unsigned long num_pages,
39
			 unsigned long num_pages,
41
			 int gmr_id)
40
			 int gmr_id)
42
{
41
{
43
	SVGAFifoCmdDefineGMR2 define_cmd;
42
	SVGAFifoCmdDefineGMR2 define_cmd;
44
	SVGAFifoCmdRemapGMR2 remap_cmd;
43
	SVGAFifoCmdRemapGMR2 remap_cmd;
45
	uint32_t define_size = sizeof(define_cmd) + 4;
44
	uint32_t define_size = sizeof(define_cmd) + 4;
46
	uint32_t remap_size = VMW_PPN_SIZE * num_pages + sizeof(remap_cmd) + 4;
45
	uint32_t remap_size = VMW_PPN_SIZE * num_pages + sizeof(remap_cmd) + 4;
47
	uint32_t *cmd;
46
	uint32_t *cmd;
48
	uint32_t *cmd_orig;
47
	uint32_t *cmd_orig;
49
	uint32_t i;
48
	uint32_t i;
50
 
49
 
51
	cmd_orig = cmd = vmw_fifo_reserve(dev_priv, define_size + remap_size);
50
	cmd_orig = cmd = vmw_fifo_reserve(dev_priv, define_size + remap_size);
52
	if (unlikely(cmd == NULL))
51
	if (unlikely(cmd == NULL))
53
		return -ENOMEM;
52
		return -ENOMEM;
54
 
53
 
55
	define_cmd.gmrId = gmr_id;
54
	define_cmd.gmrId = gmr_id;
56
	define_cmd.numPages = num_pages;
55
	define_cmd.numPages = num_pages;
57
 
56
 
58
	remap_cmd.gmrId = gmr_id;
57
	remap_cmd.gmrId = gmr_id;
59
	remap_cmd.flags = (VMW_PPN_SIZE > sizeof(*cmd)) ?
58
	remap_cmd.flags = (VMW_PPN_SIZE > sizeof(*cmd)) ?
60
		SVGA_REMAP_GMR2_PPN64 : SVGA_REMAP_GMR2_PPN32;
59
		SVGA_REMAP_GMR2_PPN64 : SVGA_REMAP_GMR2_PPN32;
61
	remap_cmd.offsetPages = 0;
60
	remap_cmd.offsetPages = 0;
62
	remap_cmd.numPages = num_pages;
61
	remap_cmd.numPages = num_pages;
63
 
62
 
64
	*cmd++ = SVGA_CMD_DEFINE_GMR2;
63
	*cmd++ = SVGA_CMD_DEFINE_GMR2;
65
	memcpy(cmd, &define_cmd, sizeof(define_cmd));
64
	memcpy(cmd, &define_cmd, sizeof(define_cmd));
66
	cmd += sizeof(define_cmd) / sizeof(uint32);
65
	cmd += sizeof(define_cmd) / sizeof(uint32);
67
 
66
 
68
	*cmd++ = SVGA_CMD_REMAP_GMR2;
67
	*cmd++ = SVGA_CMD_REMAP_GMR2;
69
	memcpy(cmd, &remap_cmd, sizeof(remap_cmd));
68
	memcpy(cmd, &remap_cmd, sizeof(remap_cmd));
70
	cmd += sizeof(remap_cmd) / sizeof(uint32);
69
	cmd += sizeof(remap_cmd) / sizeof(uint32);
71
 
70
 
72
	for (i = 0; i < num_pages; ++i) {
71
	for (i = 0; i < num_pages; ++i) {
73
		if (VMW_PPN_SIZE <= 4)
72
		if (VMW_PPN_SIZE <= 4)
74
			*cmd = page_to_pfn(*pages++);
73
			*cmd = page_to_pfn(*pages++);
75
		else
74
		else
76
			*((uint64_t *)cmd) = page_to_pfn(*pages++);
75
			*((uint64_t *)cmd) = page_to_pfn(*pages++);
77
 
76
 
78
		cmd += VMW_PPN_SIZE / sizeof(*cmd);
77
		cmd += VMW_PPN_SIZE / sizeof(*cmd);
79
	}
78
	}
80
 
79
 
81
	vmw_fifo_commit(dev_priv, define_size + remap_size);
80
	vmw_fifo_commit(dev_priv, define_size + remap_size);
82
 
81
 
83
	return 0;
82
	return 0;
84
}
83
}
85
 
84
 
86
static void vmw_gmr2_unbind(struct vmw_private *dev_priv,
85
static void vmw_gmr2_unbind(struct vmw_private *dev_priv,
87
			    int gmr_id)
86
			    int gmr_id)
88
{
87
{
89
	SVGAFifoCmdDefineGMR2 define_cmd;
88
	SVGAFifoCmdDefineGMR2 define_cmd;
90
	uint32_t define_size = sizeof(define_cmd) + 4;
89
	uint32_t define_size = sizeof(define_cmd) + 4;
91
	uint32_t *cmd;
90
	uint32_t *cmd;
92
 
91
 
93
	cmd = vmw_fifo_reserve(dev_priv, define_size);
92
	cmd = vmw_fifo_reserve(dev_priv, define_size);
94
	if (unlikely(cmd == NULL)) {
93
	if (unlikely(cmd == NULL)) {
95
		DRM_ERROR("GMR2 unbind failed.\n");
94
		DRM_ERROR("GMR2 unbind failed.\n");
96
		return;
95
		return;
97
	}
96
	}
98
	define_cmd.gmrId = gmr_id;
97
	define_cmd.gmrId = gmr_id;
99
	define_cmd.numPages = 0;
98
	define_cmd.numPages = 0;
100
 
99
 
101
	*cmd++ = SVGA_CMD_DEFINE_GMR2;
100
	*cmd++ = SVGA_CMD_DEFINE_GMR2;
102
	memcpy(cmd, &define_cmd, sizeof(define_cmd));
101
	memcpy(cmd, &define_cmd, sizeof(define_cmd));
103
 
102
 
104
	vmw_fifo_commit(dev_priv, define_size);
103
	vmw_fifo_commit(dev_priv, define_size);
105
}
104
}
106
 
105
 
107
 
106
 
108
int vmw_gmr_bind(struct vmw_private *dev_priv,
107
int vmw_gmr_bind(struct vmw_private *dev_priv,
109
		 struct page *pages[],
108
		 struct page *pages[],
110
		 unsigned long num_pages,
109
		 unsigned long num_pages,
111
		 int gmr_id)
110
		 int gmr_id)
112
{
111
{
113
	struct list_head desc_pages;
112
	struct list_head desc_pages;
114
	int ret;
113
	int ret;
115
 
114
 
116
	if (likely(dev_priv->capabilities & SVGA_CAP_GMR2))
115
	if (likely(dev_priv->capabilities & SVGA_CAP_GMR2))
117
		return vmw_gmr2_bind(dev_priv, pages, num_pages, gmr_id);
116
		return vmw_gmr2_bind(dev_priv, pages, num_pages, gmr_id);
118
 
117
 
119
    printf("%s epic fail\n",__FUNCTION__);
118
    printf("%s epic fail\n",__FUNCTION__);
120
    return -EINVAL;
119
    return -EINVAL;
121
}
120
}
122
 
121
 
123
 
122
 
124
void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id)
123
void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id)
125
{
124
{
126
	if (likely(dev_priv->capabilities & SVGA_CAP_GMR2)) {
125
	if (likely(dev_priv->capabilities & SVGA_CAP_GMR2)) {
127
		vmw_gmr2_unbind(dev_priv, gmr_id);
126
		vmw_gmr2_unbind(dev_priv, gmr_id);
128
		return;
127
		return;
129
	}
128
	}
130
 
129
 
131
	mutex_lock(&dev_priv->hw_mutex);
130
	mutex_lock(&dev_priv->hw_mutex);
132
	vmw_write(dev_priv, SVGA_REG_GMR_ID, gmr_id);
131
	vmw_write(dev_priv, SVGA_REG_GMR_ID, gmr_id);
133
	wmb();
132
	wmb();
134
	vmw_write(dev_priv, SVGA_REG_GMR_DESCRIPTOR, 0);
133
	vmw_write(dev_priv, SVGA_REG_GMR_DESCRIPTOR, 0);
135
	mb();
134
	mb();
136
	mutex_unlock(&dev_priv->hw_mutex);
135
	mutex_unlock(&dev_priv->hw_mutex);
137
}
136
}