2 * Parallel-port device support
10 #include <sys/types.h>
13 #include <sys/ioctl.h>
15 #include <linux/ppdev.h>
22 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(int);
26 typedef struct _PPDEVICESTRUCT
{
27 int fd
; /* NULL if device not available */
29 int userbase
; /* where wine thinks the ports are*/
30 DWORD lastaccess
; /* or NULL if release */
31 int timeout
; /* time in second of inactivity to release the port*/
34 static PPDeviceStruct PPDeviceList
[5];
35 static int PPDeviceNum
=0;
37 static int IO_pp_sort(const void *p1
,const void *p2
)
39 return ((PPDeviceStruct
*)p1
)->userbase
- ((PPDeviceStruct
*)p2
)->userbase
;
44 * Read the ppdev entries from wine.conf, open the device and check
45 * for nescessary IOCTRL
46 * Report verbose about possible errors
54 int i
,idx
=0,fd
,res
,userbase
,nports
=0;
60 if (RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config\\ppdev", &hkey
) != ERROR_SUCCESS
)
65 DWORD type
, count
= sizeof(buffer
), name_len
= sizeof(name
);
67 if (RegEnumValueA( hkey
, idx
, name
, &name_len
, NULL
, &type
, buffer
, &count
)!= ERROR_SUCCESS
)
73 FIXME("Make the PPDeviceList larger then 5 elements\n");
76 TRACE("Device '%s' at virtual userbase '%s'\n", buffer
,name
);
77 timeout
= strchr(buffer
,',');
80 fd
=open(buffer
,O_RDWR
);
84 WARN("Configuration: No access to %s Cause: %s\n",buffer
,strerror(lasterror
));
85 WARN("Rejecting configuration item\n");
86 if (lasterror
== ENODEV
)
87 FIXME("Is the ppdev module loaded?\n");
90 userbase
= strtol(name
,(char **)NULL
, 16);
93 WARN("Configuration: Invalid base %s for %s\n",name
,buffer
);
94 WARN("Rejecting configuration item\n");
97 if (ioctl (fd
,PPCLAIM
,0))
99 ERR("PPCLAIM rejected %s\n",buffer
);
100 ERR("Perhaps the device is already in use or non-existant\n");
105 for (i
=0; i
<= nports
; i
++)
107 if (PPDeviceList
[i
].userbase
== userbase
)
109 WARN("Configuration: %s uses the same virtual ports as %s\n",
110 buffer
,PPDeviceList
[0].devicename
);
111 WARN("Configuration: Rejecting configuration item");
116 if (!userbase
) continue;
118 /* Check for the minimum required IOCTLS */
119 if ((ioctl(fd
,PPRDATA
,&res
))||
120 (ioctl(fd
,PPRCONTROL
,&res
))||
121 (ioctl(fd
,PPRCONTROL
,&res
)))
123 ERR("PPUSER IOCTL not available for parport device %s\n",temp
);
126 if (ioctl (fd
,PPRELEASE
,0))
128 ERR("PPRELEASE rejected %s\n",buffer
);
129 ERR("Perhaps the device is already in use or non-existant\n");
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
)
185 if (ioctl(PPDeviceList
[idx
].fd
,PPCLAIM
,0))
187 ERR("Can't reclaim device %s, PPUSER/PPDEV handling confused\n",
188 PPDeviceList
[idx
].devicename
);
191 ret
= ioctl(PPDeviceList
[idx
].fd
,ppctl
,res
);
192 if (ioctl(PPDeviceList
[idx
].fd
,PPRELEASE
,0))
194 ERR("Can't release device %s, PPUSER/PPDEV handling confused\n",
195 PPDeviceList
[idx
].devicename
);
204 * Check if we can satisfy the INP command with some of the configured PPDEV deviced
205 * Return NULL on success
207 int IO_pp_inp(int port
, DWORD
* res
)
211 for (idx
=0;idx
<PPDeviceNum
;idx
++)
213 j
= port
- PPDeviceList
[idx
].userbase
;
218 return IO_pp_do_access(idx
,PPRDATA
,res
);
220 return IO_pp_do_access(idx
,PPRSTATUS
,res
);
222 return IO_pp_do_access(idx
,PPRCONTROL
,res
);
228 FIXME("Port 0x%x not accessible for reading with ppdev\n",port
);
229 FIXME("If this is causing problems, try direct port access\n");
240 * Check if we can satisfy the INP command with some of the configured PPDEV deviced
241 * Return NULL on success
243 BOOL
IO_pp_outp(int port
, DWORD
* res
)
247 for (idx
=0;idx
<PPDeviceNum
;idx
++)
249 j
= port
- PPDeviceList
[idx
].userbase
;
254 return IO_pp_do_access(idx
,PPWDATA
,res
);
256 return IO_pp_do_access(idx
,PPWCONTROL
,res
);
263 FIXME("Port %d not accessible for writing with ppdev\n",port
);
264 FIXME("If this is causing problems, try direct port access\n");
274 #else /* HAVE_PPDEV */
278 char IO_pp_init(void)
283 int IO_pp_inp(int port
, DWORD
* res
)
288 BOOL
IO_pp_outp(int port
, DWORD
* res
)
292 #endif /* HAVE_PPDEV */