2 * Parallel-port device support
7 #include "debugtools.h"
9 DEFAULT_DEBUG_CHANNEL(int);
14 #include <sys/types.h>
17 #include <sys/ioctl.h>
19 #include <linux/ppdev.h>
25 typedef struct _PPDEVICESTRUCT
{
26 int fd
; /* NULL if device not available */
28 int userbase
; /* where wine thinks the ports are*/
29 DWORD lastaccess
; /* or NULL if release */
30 int timeout
; /* time in second of inactivity to release the port*/
33 static PPDeviceStruct PPDeviceList
[5];
34 static int PPDeviceNum
=0;
36 static int IO_pp_sort(const void *p1
,const void *p2
)
38 return ((PPDeviceStruct
*)p1
)->userbase
- ((PPDeviceStruct
*)p2
)->userbase
;
43 * Read the ppdev entries from wine.conf, open the device and check
44 * for nescessary IOCTRL
45 * Report verbose about possible errors
53 int i
,idx
=0,fd
,res
,userbase
,nports
=0;
59 if (RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config\\ppdev", &hkey
) != ERROR_SUCCESS
)
64 DWORD type
, count
= sizeof(buffer
), name_len
= sizeof(name
);
66 if (RegEnumValueA( hkey
, idx
, name
, &name_len
, NULL
, &type
, buffer
, &count
)!= ERROR_SUCCESS
)
72 FIXME("Make the PPDeviceList larger then 5 elements\n");
75 TRACE("Device '%s' at virtual userbase '%s'\n", buffer
,name
);
76 timeout
= strchr(buffer
,',');
79 fd
=open(buffer
,O_RDWR
);
83 WARN("Configuration: No access to %s Cause: %s\n",buffer
,strerror(lasterror
));
84 WARN("Rejecting configuration item\n");
85 if (lasterror
== ENODEV
)
86 FIXME("Is the ppdev module loaded?\n");
89 userbase
= strtol(name
,(char **)NULL
, 16);
92 WARN("Configuration: Invalid base %s for %s\n",name
,buffer
);
93 WARN("Rejecting configuration item\n");
96 if (ioctl (fd
,PPEXCL
,0))
98 ERR("PPEXCL IOCTL rejected for device %s\n",buffer
);
99 ERR("Check that PPDEV module is loaded!\n");
100 ERR("Perhaps the device is already in use or non-existant\n");
103 if (ioctl (fd
,PPCLAIM
,0))
105 ERR("PPCLAIM rejected %s\n",buffer
);
106 ERR("Perhaps the device is already in use or non-existant\n");
111 for (i
=0; i
<= nports
; i
++)
113 if (PPDeviceList
[i
].userbase
== userbase
)
115 WARN("Configuration: %s uses the same virtual ports as %s\n",
116 buffer
,PPDeviceList
[0].devicename
);
117 WARN("Configuration: Rejecting configuration item");
122 if (!userbase
) continue;
124 /* Check for the minimum required IOCTLS */
125 if ((ioctl(fd
,PPRDATA
,&res
))||
126 (ioctl(fd
,PPRCONTROL
,&res
))||
127 (ioctl(fd
,PPRCONTROL
,&res
)))
129 ERR("PPUSER IOCTL not available for parport device %s\n",temp
);
132 PPDeviceList
[nports
].devicename
= malloc(sizeof(buffer
)+1);
133 if (!PPDeviceList
[nports
].devicename
)
135 ERR("No (more)space for devicename\n");
138 strcpy(PPDeviceList
[nports
].devicename
,buffer
);
139 PPDeviceList
[nports
].fd
= fd
;
140 PPDeviceList
[nports
].userbase
= userbase
;
141 PPDeviceList
[nports
].lastaccess
=GetTickCount();
144 PPDeviceList
[nports
].timeout
= strtol(timeout
,(char **)NULL
, 10);
147 WARN("Configuration:Invalid timeout %s in configuration for %s, Setting to 0\n",
149 PPDeviceList
[nports
].timeout
= 0;
153 PPDeviceList
[nports
].timeout
= 0;
156 TRACE("found %d ports\n",nports
);
161 /* sort in accending order for userbase for faster access*/
162 qsort (PPDeviceList
,PPDeviceNum
,sizeof(PPDeviceStruct
),IO_pp_sort
);
166 for (idx
= 0;idx
<PPDeviceNum
; idx
++)
167 TRACE("found device %s userbase %x fd %x timeout %d\n",
168 PPDeviceList
[idx
].devicename
, PPDeviceList
[idx
].userbase
,
169 PPDeviceList
[idx
].fd
,PPDeviceList
[idx
].timeout
);
171 register a timer callback perhaps every 30 second to release unused ports
172 Set lastaccess = 0 as indicator when port was released
179 * Do the actual IOCTL
180 * Return NULL on success
182 static int IO_pp_do_access(int idx
,int ppctl
, DWORD
* res
)
184 if (!PPDeviceList
[idx
].lastaccess
)
185 /* TIMER callback has released the device after some time of inactivity
187 !!!!!!THIS MAY UNINTERRUPTIPLE BLOCK IF SOME OTHER DEVICE
188 !!!!!! HAS CLAIMED THE SAME PORT
190 if (ioctl(PPDeviceList
[idx
].fd
,PPCLAIM
,0))
192 ERR("Can't reclaim device %s, PPUSER/PPDEV handling confused\n",
193 PPDeviceList
[idx
].devicename
);
196 PPDeviceList
[idx
].lastaccess
=GetTickCount();
197 return ioctl(PPDeviceList
[idx
].fd
,ppctl
,res
);
202 * Check if we can satisfy the INP command with some of the configured PPDEV deviced
203 * Return NULL on success
205 int IO_pp_inp(int port
, DWORD
* res
)
209 for (idx
=0;idx
<PPDeviceNum
;idx
++)
211 j
= port
- PPDeviceList
[idx
].userbase
;
216 return IO_pp_do_access(idx
,PPRDATA
,res
);
218 return IO_pp_do_access(idx
,PPRSTATUS
,res
);
220 return IO_pp_do_access(idx
,PPRCONTROL
,res
);
226 FIXME("Port 0x%x not accessible for reading with ppdev\n",port
);
227 FIXME("If this is causing problems, try direct port access\n");
238 * Check if we can satisfy the INP command with some of the configured PPDEV deviced
239 * Return NULL on success
241 BOOL
IO_pp_outp(int port
, DWORD
* res
)
245 for (idx
=0;idx
<PPDeviceNum
;idx
++)
247 j
= port
- PPDeviceList
[idx
].userbase
;
252 return IO_pp_do_access(idx
,PPWDATA
,res
);
254 return IO_pp_do_access(idx
,PPWCONTROL
,res
);
261 FIXME("Port %d not accessible for writing with ppdev\n",port
);
262 FIXME("If this is causing problems, try direct port access\n");
272 #else /* HAVE_PPDEV */
274 char IO_pp_init(void)
279 int IO_pp_inp(int port
, DWORD
* res
)
284 BOOL
IO_pp_outp(int port
, DWORD
* res
)
288 #endif /* HAVE_PPDEV */