summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri/unichrome/xf86drmVIA.c
blob: e39bdf745f1ca881f4b2a4ad2484d474ae505a27 (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
/*
 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sub license,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#ifdef XFree86Server
# include "xf86.h"
# include "xf86_OSproc.h"
# include "xf86_ansic.h"
# define _DRM_MALLOC xalloc
# define _DRM_FREE   xfree
# ifndef XFree86LOADER
#  include <sys/mman.h>
# endif
#else
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
# include <string.h>
# include <ctype.h>
# include <fcntl.h>
# include <errno.h>
# include <signal.h>
# include <sys/types.h>
# include <sys/ioctl.h>
# include <sys/mman.h>
# include <sys/time.h>
# ifdef DRM_USE_MALLOC
#  define _DRM_MALLOC malloc
#  define _DRM_FREE   free
extern int xf86InstallSIGIOHandler(int fd, void (*f)(int, void *), void *);
extern int xf86RemoveSIGIOHandler(int fd);
# else
#  include <X11/Xlibint.h>
#  define _DRM_MALLOC Xmalloc
#  define _DRM_FREE   Xfree
# endif
#endif

/* Not all systems have MAP_FAILED defined */
#ifndef MAP_FAILED
#define MAP_FAILED ((void *)-1)
#endif

#ifdef __linux__
#include <sys/sysmacros.h>	/* for makedev() */
#endif
#include "xf86drm.h"
#include "xf86drmVIA.h"
#include "drm.h"
#include "via_common.h"
int drmVIAAgpInit(int fd, int offset, int size)
{
    drm_via_agp_t agp;
    agp.offset = offset;
    agp.size = size;

    if (ioctl(fd, DRM_IOCTL_VIA_AGP_INIT, &agp) < 0) {
         return -errno;
    }
    else {
        return 0;
    }
}

int drmVIAFBInit(int fd, int offset, int size)
{
    drm_via_fb_t fb;
    fb.offset = offset;
    fb.size = size;

    if (ioctl(fd, DRM_IOCTL_VIA_FB_INIT, &fb) < 0) {
	return -errno;
    }
    else
	return 0;
}

int drmVIAInitMAP(int fd, drmVIAInit *info)
{
    drm_via_init_t init;

    memset(&init, 0, sizeof(drm_via_init_t));
    init.func = VIA_INIT_MAP;  
    init.sarea_priv_offset = info->sarea_priv_offset;  
    init.fb_offset = info->fb_offset;
    init.mmio_offset = info->mmio_offset;
    init.agpAddr = info->agpAddr;
   
    if (ioctl(fd, DRM_IOCTL_VIA_MAP_INIT, &init ) < 0) {
        return -errno;
    }
    else
        return 0;
}

int drmVIAAllocateDMA(int fd, drmVIADMABuf *buf)
{
    if (drmAddMap(fd, 0, buf->size,
		   DRM_SHM, 0,
		   &buf->index) < 0) {
		return -errno;
    }
    
    if (drmMap(fd,(drmHandle)buf->index,
		buf->size,(drmAddressPtr)(&buf->address)) < 0) {
	return -errno;
    }
    
    memset(buf->address, 0, buf->size);
	
    return 0;
}

int drmVIAReleaseDMA(int fd, drmVIADMABuf *buf)
{	
    if (drmUnmap((drmAddress)(buf->address), buf->size) < 0)
	return -errno;
    
    return 0;
}