StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
physmem.h
1 /*
2  * physmem.h
3  * last update: 02-Aug-2006
4  */
5 
6 #define PHYSMEM_MAJOR 122
7 #define PHYSMEM_NAME "physmem"
8 
9 #define PHYSMEM_4GB 0x100000000ULL
10 #define PHYSMEM_2GB 0x080000000L
11 #define PHYSMEM_96MB 0x006000000L
12 #define PHYSMEM_16MB 0x001000000L
13 
14 #define PHYSMEM_MAXDEVICE 2 // physmem0, physmem1
15 
16 #define PHYSMEM_GETADDR _IOR('x', 1, u_long) // get physical address
17 #define PHYSMEM_GETSIZE _IOR('x', 2, u_long) // get size in bytes
18 
19 
20 /* physmem driver for a 2.4 kernel version 3.0
21  ===============================
22 
23 INSTALLATION
24 ============
25 
26 - all commands must be done as root
27 
28 - partition the physical memory between Linux and physmem:
29  for this purpose modify the configuration file for the
30  the boot loader lilo or grub (depending on your system)
31  for grub: edit file /boot/grub/grub.conf file
32  for lilo: edit file /etc/lilo.conf, execute /sbin/lilo
33  in this file add the parameter "mem=512M" for example to
34  limit Linux to 512 MB and physmem gets the remaining memory
35 
36 - reboot the machine with
37  /sbin/shutdown -r now
38 
39 - get sources it for example in /usr/local/physmem
40 
41 - create the device file /dev/physmem0 and /dev/physmem1 with
42  gmake dev
43 
44 - compile the physmem driver and the test program with
45  gmake driver
46  gmake
47 
48 - load the driver for testing purpose with
49  /sbin/insmod physmem.o
50 
51 - optionally the parameter physmemsize in MB can be passed
52  it given the total amount of physmem
53  for example the following command assigns 100 MB
54  /sbin/insmod physmem.o physmemsize=100
55 
56 - optionally the parameter physmemsize0 in MB can be passed
57  it given the amount of physmem0, default is 128 MB
58  for example the following command assigns 16 MB
59  /sbin/insmod physmem.o physmemsize0=16
60 
61 - a test with physmemTest is recommended
62 
63 - check how much memory Linux and physmem sees
64  for Linux: cat /proc/meminfo
65  for physmem: grep physmem /var/log/messages
66 
67 - add the following line in the /etc/rc.d/rc.local file
68  to load the driver at boot time
69  /sbin/insmod /opt/physmem/physmem.o
70 
71 
72 USAGE
73 =====
74 
75 - a simple test can be done with the program physmemTest
76  it does a write-read-back test for all physmem devices
77 
78 - the API is the following using standard Linux file operations:
79 
80  #include "physmem.h"
81 
82  int err;
83  int physmem_fd;
84  void *addr_user_physmem;
85  unsigned long phys_addr_physmem;
86  unsigned long phys_size_physmem;
87 
88  1) open the device:
89  physmem_fd = open("/dev/physmem0",O_RDWR)
90 
91  2) get physical start address:
92  err = ioctl (physmem_fd, PHYSMEM_GETADDR, &physmem_addr)
93 
94  3) get available size in bytes:
95  err = ioctl (physmem_fd, PHYSMEM_GETSIZE, &physmem_size)
96 
97  4) map to user space:
98  addr_user_physmem = mmap(0,physmem_size,PROT_READ|PROT_WRITE,
99  MAP_SHARED,physmem_fd,0)
100 
101  5) unmap from user space:
102  err = munmap(physmem_addr,physmem_size)
103 
104  6) close the device:
105  err = close (physmem_fd)
106 
107 - a simple programming example can be found in physmemTest.c
108 
109 
110 */