heath@sun.com (Frank Heath) (05/07/89)
Help! This is my first driver and I have managed to get the probe, attach open, and close routines to work. We need to use several ioctl routines to move some blocks of control information to a smart board. I initially blew the _IO macros but I think I have them right now. The problem is that copyin fails with EFAULT(14) any assistence would be greatly appriciated. The test program is first, followed the revelant driver code, the console trace from the driver(n.b. the Couldn't copy), and finally the user printfs. /*TEST PROGRAM */ #include <stdio.h> #include <sys/file.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/ioctl.h> #define PRIA_MEM_SIZE 0x100000 /*Size of Board window */ #define PRIA_DATA_SIZE 0x8000 /*Size of the Data Window */ #define PRIA_RESET _IO(p,1) #define PRIA_STATISTICS _IOR(p,2,255) #define CC_SEND _IOW(p,3,struct driver_blk) #define CC_RECEIVE _IOR(p,4,struct driver_blk) #define SET_LINE_STATE _IOW(p,5,struct driver_blk) #define GET_LINE_STATE _IOR(p,6,struct driver_blk) #define PRIA_RING_READY _IO(p,7) #define PRIA_SET_RESPONCE _IOW(p,8,struct driver_blk) main() { int fd, prot, share, offset, i, j; unsigned pria_len; char *addr; int *top_pria, *top_data; int *tmp; int pagesize; char message[80]; struct driver_blk{ int isdna_num; int data_len; char payload[128]; } block; if ((fd = open("/dev/prid0", O_RDWR)) < 0 ) { perror("Dev open failed\n"); exit(1); } strcpy(block.payload,"Hello world"); block.data_len = strlen(block.payload); block.isdna_num = 0; i = ioctl(fd,CC_SEND,(char *)&block); printf("Ready ioctl return %d addr %lx %lx\n",i,block,&block); getchar(); strcpy(block.payload,""); block.data_len = 1; i = ioctl(fd,CC_SEND, block); printf("Ready ioctl return %d len %d\n",i,block.data_len); getchar(); close(fd); printf("Bye \n"); } /* DRIVER CODE */ #include "prid.h" #if NPRID > 0 #include <../sys/param.h> #include <../sys/types.h> #include <../sys/buf.h> #include <../sys/file.h> #include <../sys/dir.h> #include <../sys/user.h> #include <../sys/uio.h> #include <../sys/errno.h> #include <../sys/systm.h> #include <../sys/map.h> #include <../sys/ioctl.h> #include <../machine/psl.h> #include <../sundev/mbvar.h> #include <../machine/pte.h> #define K 1024 #include <../sundev/device_reg.h> int pria_interrupts = 0; int pridprobe(), pridopen(), pridmmap(), pridintr(); pridattach(); pridclose(); pridread(); pridwrite(); pridioctl(); pridselect(); struct mb_device *prid_info[NPRID]; struct driver_blk{ int isdna_num; int data_len; char payload[128]; } protocol_block; #define PRIA_RESET _IO(p,1) #define PRIA_STATISTICS _IOR(p,2,255) #define CC_SEND _IOW(p,3,struct driver_blk) #define CC_RECEIVE _IOR(p,4,struct driver_blk) #define SET_LINE_STATE _IOW(p,5,struct driver_blk) #define GET_LINE_STATE _IOR(p,6,struct driver_blk) #define PRIA_RING_READY _IO(p,7) #define PRIA_SET_RESPONCE _IOW(p,8,struct driver_blk) int pridioctl(dev, cmd, data, flag) dev_t dev; int cmd; caddr_t data; int flag; { register struct prid_driver *pr = &prid_driver[minor(dev)]; int rc = 0; printf("Enter IOCTL CMD = %d Flags %d\n",cmd,flag); switch(cmd) { case PRIA_RESET: rc = board_reset(pr); break; case PRIA_STATISTICS: rc = board_stats(pr,data); break; case CC_SEND: rc = put_in_ring(pr,data); break; case CC_RECEIVE: [[ Sorry, but that's how the message showed up. It may have been truncated. --wnl ]]