annotate libdha/mtrr.c @ 12387:5c2e728f5a00

keepaspect support, tryed to clean up DirectxManageDisplay a bit, enabled UYVY support and fixed bugs where switching to fullscreen would keep the console window on top and where the initial window position is wrongly calculated
author faust3
date Sat, 01 May 2004 20:21:03 +0000
parents e9bd97d5c5cc
children 243f6f5d0bb9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4476
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
1 /*
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
2 mtrr.c - Stuff for optimizing memory access
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
3 Copyrights:
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
4 2002 - Linux version by Nick Kurshev
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
5 Licence: GPL
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
6 */
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
7
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
8 #include "config.h"
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
9
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
10 #include <stdio.h>
6335
e9bd97d5c5cc warning & newline fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents: 6011
diff changeset
11 #include <string.h>
4476
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
12 #include <errno.h>
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
13 #include "libdha.h"
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
14 #include "AsmMacros.h"
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
15
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
16 #if defined (__i386__) && defined (__NetBSD__)
6011
5f020e2dc745 patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents: 5872
diff changeset
17 #include <sys/param.h>
5f020e2dc745 patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents: 5872
diff changeset
18 #if __NetBSD_Version__ > 105240000
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
19 #include <stdint.h>
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
20 #include <stdlib.h>
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
21 #include <machine/mtrr.h>
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
22 #include <machine/sysarch.h>
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
23 #endif
6011
5f020e2dc745 patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents: 5872
diff changeset
24 #endif
4476
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
25
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
26 #if defined( __i386__ )
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
27 int mtrr_set_type(unsigned base,unsigned size,int type)
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
28 {
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
29 #ifdef linux
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
30 FILE * mtrr_fd;
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
31 char * stype;
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
32 switch(type)
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
33 {
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
34 case MTRR_TYPE_UNCACHABLE: stype = "uncachable"; break;
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
35 case MTRR_TYPE_WRCOMB: stype = "write-combining"; break;
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
36 case MTRR_TYPE_WRTHROUGH: stype = "write-through"; break;
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
37 case MTRR_TYPE_WRPROT: stype = "write-protect"; break;
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
38 case MTRR_TYPE_WRBACK: stype = "write-back"; break;
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
39 default: return EINVAL;
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
40 }
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
41 mtrr_fd = fopen("/proc/mtrr","wt");
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
42 if(mtrr_fd)
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
43 {
4495
0e4cffa369e4 Be more precise
nick
parents: 4476
diff changeset
44 char sout[256];
0e4cffa369e4 Be more precise
nick
parents: 4476
diff changeset
45 unsigned wr_len;
0e4cffa369e4 Be more precise
nick
parents: 4476
diff changeset
46 sprintf(sout,"base=0x%08X size=0x%08X type=%s\n",base,size,stype);
0e4cffa369e4 Be more precise
nick
parents: 4476
diff changeset
47 wr_len = fprintf(mtrr_fd,sout);
0e4cffa369e4 Be more precise
nick
parents: 4476
diff changeset
48 /*printf("MTRR: %s\n",sout);*/
4476
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
49 fclose(mtrr_fd);
4495
0e4cffa369e4 Be more precise
nick
parents: 4476
diff changeset
50 return wr_len == strlen(sout) ? 0 : EPERM;
4476
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
51 }
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
52 return ENOSYS;
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
53 #elif defined (__NetBSD__)
6011
5f020e2dc745 patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents: 5872
diff changeset
54 #if __NetBSD_Version__ > 105240000
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
55 struct mtrr *mtrrp;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
56 int n;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
57
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
58 mtrrp = malloc(sizeof (struct mtrr));
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
59 mtrrp->base = base;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
60 mtrrp->len = size;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
61 mtrrp->type = type;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
62 mtrrp->flags = MTRR_VALID | MTRR_PRIVATE;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
63 n = 1;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
64
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
65 if (i386_set_mtrr(mtrrp, &n) < 0) {
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
66 free(mtrrp);
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
67 return errno;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
68 }
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
69 free(mtrrp);
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 4510
diff changeset
70 return 0;
4476
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
71 #else
6011
5f020e2dc745 patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents: 5872
diff changeset
72 /* NetBSD prior to 1.5Y doesn't have MTRR support */
5f020e2dc745 patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents: 5872
diff changeset
73 return ENOSYS;
5f020e2dc745 patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents: 5872
diff changeset
74 #endif
5f020e2dc745 patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents: 5872
diff changeset
75 #else
4476
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
76 #warning Please port MTRR stuff!!!
4510
1f0282f9a723 fix typo
nexus
parents: 4495
diff changeset
77 return ENOSYS;
4476
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
78 #endif
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
79 }
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
80 #else
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
81 int mtrr_set_type(unsigned base,unsigned size,int type)
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
82 {
4495
0e4cffa369e4 Be more precise
nick
parents: 4476
diff changeset
83 return ENOSYS;
4476
0d9a096cfd46 MTRR configuring
nick
parents:
diff changeset
84 }
6335
e9bd97d5c5cc warning & newline fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents: 6011
diff changeset
85 #endif