Mercurial > mplayer.hg
annotate libdha/mtrr.c @ 6069:8e88e92fe331
Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
author | albeu |
---|---|
date | Mon, 13 May 2002 13:15:40 +0000 |
parents | 5f020e2dc745 |
children | e9bd97d5c5cc |
rev | line source |
---|---|
4476 | 1 /* |
2 mtrr.c - Stuff for optimizing memory access | |
3 Copyrights: | |
4 2002 - Linux version by Nick Kurshev | |
5 Licence: GPL | |
6 */ | |
7 | |
8 #include "config.h" | |
9 | |
10 #include <stdio.h> | |
11 #include <errno.h> | |
12 #include "libdha.h" | |
13 #include "AsmMacros.h" | |
14 | |
5872 | 15 #if defined (__i386__) && defined (__NetBSD__) |
6011
5f020e2dc745
patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents:
5872
diff
changeset
|
16 #include <sys/param.h> |
5f020e2dc745
patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents:
5872
diff
changeset
|
17 #if __NetBSD_Version__ > 105240000 |
5872 | 18 #include <stdint.h> |
19 #include <stdlib.h> | |
20 #include <machine/mtrr.h> | |
21 #include <machine/sysarch.h> | |
22 #endif | |
6011
5f020e2dc745
patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents:
5872
diff
changeset
|
23 #endif |
4476 | 24 |
25 #if defined( __i386__ ) | |
26 int mtrr_set_type(unsigned base,unsigned size,int type) | |
27 { | |
28 #ifdef linux | |
29 FILE * mtrr_fd; | |
30 char * stype; | |
31 switch(type) | |
32 { | |
33 case MTRR_TYPE_UNCACHABLE: stype = "uncachable"; break; | |
34 case MTRR_TYPE_WRCOMB: stype = "write-combining"; break; | |
35 case MTRR_TYPE_WRTHROUGH: stype = "write-through"; break; | |
36 case MTRR_TYPE_WRPROT: stype = "write-protect"; break; | |
37 case MTRR_TYPE_WRBACK: stype = "write-back"; break; | |
38 default: return EINVAL; | |
39 } | |
40 mtrr_fd = fopen("/proc/mtrr","wt"); | |
41 if(mtrr_fd) | |
42 { | |
4495 | 43 char sout[256]; |
44 unsigned wr_len; | |
45 sprintf(sout,"base=0x%08X size=0x%08X type=%s\n",base,size,stype); | |
46 wr_len = fprintf(mtrr_fd,sout); | |
47 /*printf("MTRR: %s\n",sout);*/ | |
4476 | 48 fclose(mtrr_fd); |
4495 | 49 return wr_len == strlen(sout) ? 0 : EPERM; |
4476 | 50 } |
51 return ENOSYS; | |
5872 | 52 #elif defined (__NetBSD__) |
6011
5f020e2dc745
patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents:
5872
diff
changeset
|
53 #if __NetBSD_Version__ > 105240000 |
5872 | 54 struct mtrr *mtrrp; |
55 int n; | |
56 | |
57 mtrrp = malloc(sizeof (struct mtrr)); | |
58 mtrrp->base = base; | |
59 mtrrp->len = size; | |
60 mtrrp->type = type; | |
61 mtrrp->flags = MTRR_VALID | MTRR_PRIVATE; | |
62 n = 1; | |
63 | |
64 if (i386_set_mtrr(mtrrp, &n) < 0) { | |
65 free(mtrrp); | |
66 return errno; | |
67 } | |
68 free(mtrrp); | |
69 return 0; | |
4476 | 70 #else |
6011
5f020e2dc745
patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents:
5872
diff
changeset
|
71 /* 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
|
72 return ENOSYS; |
5f020e2dc745
patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents:
5872
diff
changeset
|
73 #endif |
5f020e2dc745
patchs for NetBSD by Bernd Ernesti <mplayer@lists.veego.de>:
pl
parents:
5872
diff
changeset
|
74 #else |
4476 | 75 #warning Please port MTRR stuff!!! |
4510 | 76 return ENOSYS; |
4476 | 77 #endif |
78 } | |
79 #else | |
80 int mtrr_set_type(unsigned base,unsigned size,int type) | |
81 { | |
4495 | 82 return ENOSYS; |
4476 | 83 } |
84 #endif |