00001 /* 00002 * physmem.h 00003 * last update: 02-Aug-2006 00004 */ 00005 00006 #define PHYSMEM_MAJOR 122 00007 #define PHYSMEM_NAME "physmem" 00008 00009 #define PHYSMEM_4GB 0x100000000ULL 00010 #define PHYSMEM_2GB 0x080000000L 00011 #define PHYSMEM_96MB 0x006000000L 00012 #define PHYSMEM_16MB 0x001000000L 00013 00014 #define PHYSMEM_MAXDEVICE 2 // physmem0, physmem1 00015 00016 #define PHYSMEM_GETADDR _IOR('x', 1, u_long) // get physical address 00017 #define PHYSMEM_GETSIZE _IOR('x', 2, u_long) // get size in bytes 00018 00019 00020 /* physmem driver for a 2.4 kernel version 3.0 00021 =============================== 00022 00023 INSTALLATION 00024 ============ 00025 00026 - all commands must be done as root 00027 00028 - partition the physical memory between Linux and physmem: 00029 for this purpose modify the configuration file for the 00030 the boot loader lilo or grub (depending on your system) 00031 for grub: edit file /boot/grub/grub.conf file 00032 for lilo: edit file /etc/lilo.conf, execute /sbin/lilo 00033 in this file add the parameter "mem=512M" for example to 00034 limit Linux to 512 MB and physmem gets the remaining memory 00035 00036 - reboot the machine with 00037 /sbin/shutdown -r now 00038 00039 - get sources it for example in /usr/local/physmem 00040 00041 - create the device file /dev/physmem0 and /dev/physmem1 with 00042 gmake dev 00043 00044 - compile the physmem driver and the test program with 00045 gmake driver 00046 gmake 00047 00048 - load the driver for testing purpose with 00049 /sbin/insmod physmem.o 00050 00051 - optionally the parameter physmemsize in MB can be passed 00052 it given the total amount of physmem 00053 for example the following command assigns 100 MB 00054 /sbin/insmod physmem.o physmemsize=100 00055 00056 - optionally the parameter physmemsize0 in MB can be passed 00057 it given the amount of physmem0, default is 128 MB 00058 for example the following command assigns 16 MB 00059 /sbin/insmod physmem.o physmemsize0=16 00060 00061 - a test with physmemTest is recommended 00062 00063 - check how much memory Linux and physmem sees 00064 for Linux: cat /proc/meminfo 00065 for physmem: grep physmem /var/log/messages 00066 00067 - add the following line in the /etc/rc.d/rc.local file 00068 to load the driver at boot time 00069 /sbin/insmod /opt/physmem/physmem.o 00070 00071 00072 USAGE 00073 ===== 00074 00075 - a simple test can be done with the program physmemTest 00076 it does a write-read-back test for all physmem devices 00077 00078 - the API is the following using standard Linux file operations: 00079 00080 #include "physmem.h" 00081 00082 int err; 00083 int physmem_fd; 00084 void *addr_user_physmem; 00085 unsigned long phys_addr_physmem; 00086 unsigned long phys_size_physmem; 00087 00088 1) open the device: 00089 physmem_fd = open("/dev/physmem0",O_RDWR) 00090 00091 2) get physical start address: 00092 err = ioctl (physmem_fd, PHYSMEM_GETADDR, &physmem_addr) 00093 00094 3) get available size in bytes: 00095 err = ioctl (physmem_fd, PHYSMEM_GETSIZE, &physmem_size) 00096 00097 4) map to user space: 00098 addr_user_physmem = mmap(0,physmem_size,PROT_READ|PROT_WRITE, 00099 MAP_SHARED,physmem_fd,0) 00100 00101 5) unmap from user space: 00102 err = munmap(physmem_addr,physmem_size) 00103 00104 6) close the device: 00105 err = close (physmem_fd) 00106 00107 - a simple programming example can be found in physmemTest.c 00108 00109 00110 */
1.5.9