Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help using physmap in device driver

3 views
Skip to first unread message

Hoysch...

unread,
Jan 4, 1995, 11:36:35 AM1/4/95
to
I am trying to write a device driver that will provide me access 8K of
physical memory starting at 0xD0000. The Operating System is Unixware
1.1 USL Unix System V Revision 4.2 Version 1.1.1. I read the
documentation and thought physmap was the kernel routine that I needed
to accomplish my task. Well I wrote and built the Device Driver and
tried to test it. The Device Driver returns a value that I receive
correctly (determined via debug print statements), but when I try to
write into the address returned I get segmant error (core dumped).
I would appreciate it if anyone could give me a clue as to what I
am doing incorrect. I am including the code in hopes that someone
(anyone can help). If you have any suggestions, please send me E-mail.

Thanks, Dan "Hoysch" Heuschele
E-mail hoy...@manta.nosc.mil


/* map.c : Device Driver to provide access to shared memory on */
/* smart I/O card */
#include <sys/types.h> /* required for physmap */
#include <sys/kmem.h> /* required for physmap */

#include <sys/param.h>
#include <sys/systm.h>

#include <sys/dir.h>
#include <sys/user.h>
#include <sys/file.h>
#include <sys/immu.h>

#include <sys/cmn_err.h>

#include <sys/tty.h>
#include <sys/errno.h>
#include <sys/conf.h>
#include <sys/cred.h>
#include <sys/ddi.h>

#define PHYS_ADDR 0xD0000L; /* System Memory boundry */
#define MEM_SIZE 0x8000L; /* 8 Kb of space */

/*#define DEBUG*/

int mmapdevflag = D_NEW; /* Indicates a "new" style driver */

mmapinit()
{
printf ("Initialize MAP Driver\n");
}

mmapopen(dev, flag, open)
int dev, flag, open;
{
#ifdef DEBUG
/*printf ("DEVICE: MAP opened\n");*/
cmn_err (CE_CONT, "DEVICE: MAP opened\n");
#endif DEBUG
return 0;
}

mmapclose()
{
#ifdef DEBUG
/*printf ("DEVICE: MAP closed\n");*/
cmn_err (CE_CONT, "DEVICE: MAP closeded\n");
#endif DEBUG
return 0;
}

void *mmapioctl(dev, cmd, argp)
dev_t dev;
int cmd;
int *argp;
{
*argp = physmap (0xD0000, 0x8000, KM_NOSLEEP);
#ifdef DEBUG
cmn_err (CE_CONT, "DEVICE: MAP ioctl returning %x\n", *argp);
#endif DEBUG
return *argp;
} /* mmapioctl */

/************* tmap.c : used to test mmap device driver *****************/
#include <sys/types.h>
#include <sys/param.h>
#include <fcntl.h>

#define DEVICE "/dev/mmap"
#define PARAM 0

main()
{
int fd; /* File descriptor to open device */
char *my_point;
char *my_point2;

printf ("PROCESS: opening device\n");
if ((fd = open(DEVICE, O_RDWR)) == -1)
perror ("tmap: error opening /dev/mmap");

/*
* Do an ioctl() to get the selector from the driver
*/
printf ("PROCESS: Before got address : my_point2 = %x\n", my_point2);
my_point = (char *) ioctl(fd, PARAM, &my_point2);
printf ("PROCESS: After got address : my_point = %x\n", my_point);
printf ("PROCESS: After got address : my_point2 = %x\n", my_point2);
printf ("Before assignment to my_point2\n");
*my_point2 = 0xde;
printf ("After assignment to my_point2\n"); /* <== Never prints this */
printf("PROCESS: Closing device\n");
close (fd);

printf("PROCESS: Test completed\n");
}

Thanks Again, Dan "Hoysch" Heuschele


0 new messages