VirtualBox

source: vbox/trunk/src/VBox/Devices/Parallel/DrvHostParallel.cpp@ 62618

Last change on this file since 62618 was 62618, checked in by vboxsync, 9 years ago

Devices: unused parameter warnings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 36.6 KB
Line 
1/* $Id: DrvHostParallel.cpp 62618 2016-07-28 11:23:36Z vboxsync $ */
2/** @file
3 * VirtualBox Host Parallel Port Driver.
4 *
5 * Initial Linux-only code contributed by: Alexander Eichner
6 */
7
8/*
9 * Copyright (C) 2006-2016 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.215389.xyz. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20
21/*********************************************************************************************************************************
22* Header Files *
23*********************************************************************************************************************************/
24#define LOG_GROUP LOG_GROUP_DRV_HOST_PARALLEL
25#include <VBox/vmm/pdmdrv.h>
26#include <VBox/vmm/pdmthread.h>
27#include <iprt/asm.h>
28#include <iprt/assert.h>
29#include <iprt/file.h>
30#include <iprt/pipe.h>
31#include <iprt/semaphore.h>
32#include <iprt/stream.h>
33#include <iprt/uuid.h>
34#include <iprt/cdefs.h>
35#include <iprt/ctype.h>
36
37#ifdef RT_OS_LINUX
38# include <sys/ioctl.h>
39# include <sys/types.h>
40# include <sys/stat.h>
41# include <sys/poll.h>
42# include <fcntl.h>
43# include <unistd.h>
44# include <linux/ppdev.h>
45# include <linux/parport.h>
46# include <errno.h>
47#endif
48
49/** @def VBOX_WITH_WIN_PARPORT_SUP *
50 * Indicates whether to use the generic direct hardware access or host specific
51 * code to access the parallel port.
52 */
53#if defined(RT_OS_LINUX)
54# undef VBOX_WITH_WIN_PARPORT_SUP
55#elif defined(RT_OS_WINDOWS)
56#else
57# error "Not ported"
58#endif
59
60#if defined(VBOX_WITH_WIN_PARPORT_SUP) && defined(IN_RING0)
61# include <iprt/asm-amd64-x86.h>
62#endif
63
64#if defined(VBOX_WITH_WIN_PARPORT_SUP) && defined(IN_RING3)
65# include <Windows.h>
66# include <setupapi.h>
67# include <cfgmgr32.h>
68# include <iprt/mem.h>
69# include <iprt/string.h>
70#endif
71
72#include "VBoxDD.h"
73
74
75/*********************************************************************************************************************************
76* Structures and Typedefs *
77*********************************************************************************************************************************/
78/**
79 * Host parallel port driver instance data.
80 * @implements PDMIHOSTPARALLELCONNECTOR
81 */
82typedef struct DRVHOSTPARALLEL
83{
84 /** Pointer to the driver instance structure. */
85 PPDMDRVINS pDrvIns;
86 /** Pointer to the driver instance. */
87 PPDMDRVINSR3 pDrvInsR3;
88 PPDMDRVINSR0 pDrvInsR0;
89 /** Pointer to the char port interface of the driver/device above us. */
90 PPDMIHOSTPARALLELPORT pDrvHostParallelPort;
91 /** Our host device interface. */
92 PDMIHOSTPARALLELCONNECTOR IHostParallelConnector;
93 /** Our host device interface. */
94 PDMIHOSTPARALLELCONNECTOR IHostParallelConnectorR3;
95 /** Device Path */
96 char *pszDevicePath;
97 /** Device Handle */
98 RTFILE hFileDevice;
99#ifndef VBOX_WITH_WIN_PARPORT_SUP
100 /** Thread waiting for interrupts. */
101 PPDMTHREAD pMonitorThread;
102 /** Wakeup pipe read end. */
103 RTPIPE hWakeupPipeR;
104 /** Wakeup pipe write end. */
105 RTPIPE hWakeupPipeW;
106 /** Current mode the parallel port is in. */
107 PDMPARALLELPORTMODE enmModeCur;
108#endif
109
110#ifdef VBOX_WITH_WIN_PARPORT_SUP
111 /** Data register. */
112 uint32_t u32LptAddr;
113 /** Status register. */
114 uint32_t u32LptAddrStatus;
115 /** Control register. */
116 uint32_t u32LptAddrControl;
117 /** Data read buffer. */
118 uint8_t u8ReadIn;
119 /** Control read buffer. */
120 uint8_t u8ReadInControl;
121 /** Status read buffer. */
122 uint8_t u8ReadInStatus;
123 /** Parallel port name */
124 char szParportName[6];
125 /** Whether the parallel port is available or not. */
126 bool fParportAvail;
127 /** Device Handle */
128 RTFILE hWinFileDevice;
129#endif /* VBOX_WITH_WIN_PARPORT_SUP */
130} DRVHOSTPARALLEL, *PDRVHOSTPARALLEL;
131
132
133/**
134 * Ring-0 operations.
135 */
136typedef enum DRVHOSTPARALLELR0OP
137{
138 /** Invalid zero value. */
139 DRVHOSTPARALLELR0OP_INVALID = 0,
140 /** Perform R0 initialization. */
141 DRVHOSTPARALLELR0OP_INITR0STUFF,
142 /** Read data. */
143 DRVHOSTPARALLELR0OP_READ,
144 /** Read status register. */
145 DRVHOSTPARALLELR0OP_READSTATUS,
146 /** Read control register. */
147 DRVHOSTPARALLELR0OP_READCONTROL,
148 /** Write data. */
149 DRVHOSTPARALLELR0OP_WRITE,
150 /** Write control register. */
151 DRVHOSTPARALLELR0OP_WRITECONTROL,
152 /** Set port direction. */
153 DRVHOSTPARALLELR0OP_SETPORTDIRECTION
154} DRVHOSTPARALLELR0OP;
155
156/** Converts a pointer to DRVHOSTPARALLEL::IHostDeviceConnector to a PDRHOSTPARALLEL. */
157#define PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface) ( (PDRVHOSTPARALLEL)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector))) )
158
159
160/*********************************************************************************************************************************
161* Defined Constants And Macros *
162*********************************************************************************************************************************/
163#define CTRL_REG_OFFSET 2
164#define STATUS_REG_OFFSET 1
165#define LPT_CONTROL_ENABLE_BIDIRECT 0x20
166
167
168
169#ifdef VBOX_WITH_WIN_PARPORT_SUP
170# ifdef IN_RING0
171
172/**
173 * R0 mode function to write byte value to data port.
174 *
175 * @returns VBox status code.
176 * @param pDrvIns Driver instance.
177 * @param u64Arg Data to be written to data register.
178 *
179 */
180static int drvR0HostParallelReqWrite(PPDMDRVINS pDrvIns, uint64_t u64Arg)
181{
182 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
183 LogFlowFunc(("write to data port=%#x val=%#x\n", pThis->u32LptAddr, u64Arg));
184 ASMOutU8(pThis->u32LptAddr, (uint8_t)(u64Arg));
185 return VINF_SUCCESS;
186}
187
188/**
189 * R0 mode function to write byte value to parallel port control register.
190 *
191 * @returns VBox status code.
192 * @param pDrvIns Driver instance.
193 * @param u64Arg Data to be written to control register.
194 */
195static int drvR0HostParallelReqWriteControl(PPDMDRVINS pDrvIns, uint64_t u64Arg)
196{
197 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
198 LogFlowFunc(("write to ctrl port=%#x val=%#x\n", pThis->u32LptAddrControl, u64Arg));
199 ASMOutU8(pThis->u32LptAddrControl, (uint8_t)(u64Arg));
200 return VINF_SUCCESS;
201}
202
203/**
204 * R0 mode function to ready byte value from the parallel port data register.
205 *
206 * @returns VBox status code.
207 * @param pDrvIns Driver instance.
208 */
209static int drvR0HostParallelReqRead(PPDMDRVINS pDrvIns)
210{
211 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
212 uint8_t u8Data = ASMInU8(pThis->u32LptAddr);
213 LogFlowFunc(("read from data port=%#x val=%#x\n", pThis->u32LptAddr, u8Data));
214 pThis->u8ReadIn = u8Data;
215 return VINF_SUCCESS;
216}
217
218/**
219 * R0 mode function to ready byte value from the parallel port control register.
220 *
221 * @returns VBox status code.
222 * @param pDrvIns Driver instance.
223 */
224static int drvR0HostParallelReqReadControl(PPDMDRVINS pDrvIns)
225{
226 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
227 uint8_t u8Data = ASMInU8(pThis->u32LptAddrControl);
228 LogFlowFunc(("read from ctrl port=%#x val=%#x\n", pThis->u32LptAddr, u8Data));
229 pThis->u8ReadInControl = u8Data;
230 return VINF_SUCCESS;
231}
232
233/**
234 * R0 mode function to ready byte value from the parallel port status register.
235 *
236 * @returns VBox status code.
237 * @param pDrvIns Driver instance.
238 */
239static int drvR0HostParallelReqReadStatus(PPDMDRVINS pDrvIns)
240{
241 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
242 uint8_t u8Data = ASMInU8(pThis->u32LptAddrStatus);
243 LogFlowFunc(("read from status port=%#x val=%#x\n", pThis->u32LptAddr, u8Data));
244 pThis->u8ReadInStatus = u8Data;
245 return VINF_SUCCESS;
246}
247
248/**
249 * R0 mode function to set the direction of parallel port -
250 * operate in bidirectional mode or single direction.
251 *
252 * @returns VBox status code.
253 * @param pDrvIns Driver instance.
254 * @param u64Arg Mode.
255 */
256static int drvR0HostParallelReqSetPortDir(PPDMDRVINS pDrvIns, uint64_t u64Arg)
257{
258 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
259 uint8_t u8ReadControlVal;
260 uint8_t u8WriteControlVal;
261
262 if (u64Arg)
263 {
264 u8ReadControlVal = ASMInU8(pThis->u32LptAddrControl);
265 u8WriteControlVal = u8ReadControlVal | LPT_CONTROL_ENABLE_BIDIRECT; /* enable input direction */
266 ASMOutU8(pThis->u32LptAddrControl, u8WriteControlVal);
267 }
268 else
269 {
270 u8ReadControlVal = ASMInU8(pThis->u32LptAddrControl);
271 u8WriteControlVal = u8ReadControlVal & ~LPT_CONTROL_ENABLE_BIDIRECT; /* disable input direction */
272 ASMOutU8(pThis->u32LptAddrControl, u8WriteControlVal);
273 }
274 return VINF_SUCCESS;
275}
276
277/**
278 * @interface_method_impl{FNPDMDRVREQHANDLERR0}
279 */
280PDMBOTHCBDECL(int) drvR0HostParallelReqHandler(PPDMDRVINS pDrvIns, uint32_t uOperation, uint64_t u64Arg)
281{
282 int rc;
283
284 LogFlowFuncEnter();
285 /* I have included break after each case. Need to work on this. */
286 switch ((DRVHOSTPARALLELR0OP)uOperation)
287 {
288 case DRVHOSTPARALLELR0OP_READ:
289 rc = drvR0HostParallelReqRead(pDrvIns);
290 break;
291 case DRVHOSTPARALLELR0OP_READSTATUS:
292 rc = drvR0HostParallelReqReadStatus(pDrvIns);
293 break;
294 case DRVHOSTPARALLELR0OP_READCONTROL:
295 rc = drvR0HostParallelReqReadControl(pDrvIns);
296 break;
297 case DRVHOSTPARALLELR0OP_WRITE:
298 rc = drvR0HostParallelReqWrite(pDrvIns, u64Arg);
299 break;
300 case DRVHOSTPARALLELR0OP_WRITECONTROL:
301 rc = drvR0HostParallelReqWriteControl(pDrvIns, u64Arg);
302 break;
303 case DRVHOSTPARALLELR0OP_SETPORTDIRECTION:
304 rc = drvR0HostParallelReqSetPortDir(pDrvIns, u64Arg);
305 break;
306 default: /* not supported */
307 rc = VERR_NOT_SUPPORTED;
308 }
309 LogFlowFuncLeave();
310 return rc;
311}
312
313# endif /* IN_RING0 */
314#endif /* VBOX_WITH_WIN_PARPORT_SUP */
315
316#ifdef IN_RING3
317# ifdef VBOX_WITH_WIN_PARPORT_SUP
318
319/**
320 * Find IO port range for the parallel port and return the lower address.
321 *
322 * @returns parallel port IO address.
323 * @param DevInst Device Instance for parallel port.
324 */
325static uint32_t drvHostWinFindIORangeResource(const DEVINST DevInst)
326{
327 uint8_t *pBuf = NULL;
328 short wHeaderSize;
329 uint32_t u32Size;
330 CONFIGRET cmRet;
331 LOG_CONF firstLogConf;
332 LOG_CONF nextLogConf;
333 RES_DES rdPrevResDes;
334 uint32_t u32ParportAddr = 0;
335
336 wHeaderSize = sizeof(IO_DES);
337 cmRet = CM_Get_First_Log_Conf(&firstLogConf, DevInst, ALLOC_LOG_CONF);
338 if (cmRet != CR_SUCCESS)
339 {
340 cmRet = CM_Get_First_Log_Conf(&firstLogConf, DevInst, BOOT_LOG_CONF);
341 if (cmRet != CR_SUCCESS)
342 return 0;
343 }
344 cmRet = CM_Get_Next_Res_Des(&nextLogConf, firstLogConf, 2, 0L, 0L);
345 if (cmRet != CR_SUCCESS)
346 {
347 CM_Free_Res_Des_Handle(firstLogConf);
348 return 0;
349 }
350 /* This loop is based on the fact that only one resourece is assigned to
351 * the LPT port. If multiple resources (address range) are assigned to
352 * to LPT port, it will pick and return the last one
353 */
354 for (;;)
355 {
356 u32Size = 0;
357 cmRet = CM_Get_Res_Des_Data_Size((PULONG)(&u32Size), nextLogConf, 0L);
358 if (cmRet != CR_SUCCESS)
359 {
360 LogFlowFunc(("Failed to get Size \n"));
361 CM_Free_Res_Des_Handle(nextLogConf);
362 break;
363 }
364
365 pBuf = (uint8_t *)RTMemAlloc(u32Size + 1);
366 if (!pBuf)
367 {
368 LogFlowFunc(("Failed to get Buf %d\n", u32Size));
369 CM_Free_Res_Des_Handle(nextLogConf);
370 break;
371 }
372 cmRet = CM_Get_Res_Des_Data(nextLogConf, pBuf, u32Size, 0L);
373 if (cmRet != CR_SUCCESS)
374 {
375 LogFlowFunc(("Failed to get Des Data \n"));
376 CM_Free_Res_Des_Handle(nextLogConf);
377 if (pBuf)
378 RTMemFree(pBuf);
379 break;
380 }
381
382 LogFlowFunc(("call GetIOResource\n"));
383 if (pBuf)
384 u32ParportAddr = ((IO_DES *)pBuf)->IOD_Alloc_Base;
385 LogFlowFunc(("called GetIOResource, ret=%#x\n", u32ParportAddr));
386 rdPrevResDes = 0;
387 cmRet = CM_Get_Next_Res_Des(&rdPrevResDes,
388 nextLogConf,
389 2,
390 0L,
391 0L);
392 if (pBuf)
393 RTMemFree(pBuf);
394 if (cmRet != CR_SUCCESS)
395 break;
396
397 CM_Free_Res_Des_Handle(nextLogConf);
398 nextLogConf = rdPrevResDes;
399 }
400 CM_Free_Res_Des_Handle(nextLogConf);
401 LogFlowFunc(("return u32ParportAddr=%#x", u32ParportAddr));
402 return u32ParportAddr;
403}
404
405/**
406 * Get Parallel port address and update the shared data
407 * structure.
408 * @returns VBox status code.
409 * @param pThis The host parallel port instance data.
410 */
411static int drvWinHostGetparportAddr(PDRVHOSTPARALLEL pThis)
412{
413 HDEVINFO hDevInfo;
414 SP_DEVINFO_DATA DeviceInfoData;
415 uint32_t u32Idx;
416 uint32_t u32ParportAddr;
417 int rc = VINF_SUCCESS;
418
419 hDevInfo = SetupDiGetClassDevs(NULL, 0, 0, DIGCF_PRESENT | DIGCF_ALLCLASSES);
420 if (hDevInfo == INVALID_HANDLE_VALUE)
421 return VERR_INVALID_HANDLE;
422
423 /* Enumerate through all devices in Set. */
424 DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
425 for (u32Idx = 0; SetupDiEnumDeviceInfo(hDevInfo, u32Idx, &DeviceInfoData); u32Idx++)
426 {
427 DWORD dwDataType;
428 uint8_t *pBuf = NULL;
429 DWORD dwBufSize = 0;
430
431 while (!SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME,
432 (PDWORD)&dwDataType, (uint8_t *)pBuf,
433 dwBufSize, (PDWORD)&dwBufSize))
434 {
435 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
436 {
437 LogFlow(("ERROR_INSUFF_BUFF = %d. dwBufSz = %d\n", GetLastError(), dwBufSize));
438 if (pBuf)
439 RTMemFree(pBuf);
440 pBuf = (uint8_t *)RTMemAlloc(dwBufSize * 2);
441 }
442 else
443 {
444 /* No need to bother about this error (in most cases its errno=13,
445 * INVALID_DATA . Just break from here and proceed to next device
446 * enumerated item
447 */
448 LogFlow(("GetDevProp Error = %d & dwBufSz = %d\n", GetLastError(), dwBufSize));
449 break;
450 }
451 }
452
453 if (RTStrStr((char*)pBuf, "LPT"))
454 {
455 u32ParportAddr = drvHostWinFindIORangeResource(DeviceInfoData.DevInst);
456 if (u32ParportAddr)
457 {
458 /* Find parallel port name and update the shared data struncture */
459 char *pCh = RTStrStr((char*)pBuf, "(");
460 char *pTmpCh = RTStrStr((char *)pBuf, ")");
461 /* check for the confirmation for the availability of parallel port */
462 if (!(pCh && pTmpCh))
463 {
464 LogFlowFunc(("Parallel port Not Found. \n"));
465 return VERR_NOT_FOUND;
466
467 }
468 if (((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) < 0) {
469 LogFlowFunc(("Parallel port string not properly formatted.\n"));
470 return VERR_NOT_FOUND;
471 }
472 /* check for the confirmation for the availability of parallel port */
473 if (RTStrCopyEx((char *)(pThis->szParportName), sizeof(pThis->szParportName),
474 pCh+1, ((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) - 1))
475 {
476 LogFlowFunc(("Parallel Port Not Found.\n"));
477 return VERR_NOT_FOUND;
478 }
479 *((char *)pThis->szParportName + (pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf) + 1 ) = '\0';
480
481 /* checking again to make sure that we have got a valid name and in valid format too. */
482 if (RTStrNCmp((char *)pThis->szParportName, "LPT", 3)) {
483 LogFlowFunc(("Parallel Port name \"LPT\" Not Found.\n"));
484 return VERR_NOT_FOUND;
485 }
486 if (!RTStrStr((char *)pThis->szParportName, "LPT")
487 || !(pThis->szParportName[3] >= '0'
488 && pThis->szParportName[3] <= '9'))
489 {
490 RT_BZERO(pThis->szParportName, sizeof(pThis->szParportName));
491 LogFlowFunc(("Printer Port Name Not Found.\n"));
492 return VERR_NOT_FOUND;
493 }
494 pThis->fParportAvail = true;
495 pThis->u32LptAddr = u32ParportAddr;
496 pThis->u32LptAddrControl = pThis->u32LptAddr + CTRL_REG_OFFSET;
497 pThis->u32LptAddrStatus = pThis->u32LptAddr + STATUS_REG_OFFSET;
498 }
499 else
500 LogFlowFunc(("u32Parport Addr No Available \n"));
501 if (pThis->fParportAvail)
502 break;
503 }
504 if (pBuf)
505 RTMemFree(pBuf);
506 if (pThis->fParportAvail)
507 {
508 /* Parallel port address has been found. No need to iterate further. */
509 break;
510 }
511 }
512
513 if (GetLastError() != NO_ERROR && GetLastError() != ERROR_NO_MORE_ITEMS)
514 rc = VERR_GENERAL_FAILURE;
515
516 SetupDiDestroyDeviceInfoList(hDevInfo);
517 return rc;
518
519}
520# endif /* VBOX_WITH_WIN_PARPORT_SUP */
521
522/**
523 * Changes the current mode of the host parallel port.
524 *
525 * @returns VBox status code.
526 * @param pThis The host parallel port instance data.
527 * @param enmMode The mode to change the port to.
528 */
529static int drvHostParallelSetMode(PDRVHOSTPARALLEL pThis, PDMPARALLELPORTMODE enmMode)
530{
531 int iMode = 0;
532 int rc = VINF_SUCCESS;
533 LogFlowFunc(("mode=%d\n", enmMode));
534
535# ifndef VBOX_WITH_WIN_PARPORT_SUP
536 int rcLnx;
537 if (pThis->enmModeCur != enmMode)
538 {
539 switch (enmMode)
540 {
541 case PDM_PARALLEL_PORT_MODE_SPP:
542 iMode = IEEE1284_MODE_COMPAT;
543 break;
544 case PDM_PARALLEL_PORT_MODE_EPP_DATA:
545 iMode = IEEE1284_MODE_EPP | IEEE1284_DATA;
546 break;
547 case PDM_PARALLEL_PORT_MODE_EPP_ADDR:
548 iMode = IEEE1284_MODE_EPP | IEEE1284_ADDR;
549 break;
550 case PDM_PARALLEL_PORT_MODE_ECP:
551 case PDM_PARALLEL_PORT_MODE_INVALID:
552 default:
553 return VERR_NOT_SUPPORTED;
554 }
555
556 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPSETMODE, &iMode);
557 if (RT_UNLIKELY(rcLnx < 0))
558 rc = RTErrConvertFromErrno(errno);
559 else
560 pThis->enmModeCur = enmMode;
561 }
562
563 return rc;
564# else /* VBOX_WITH_WIN_PARPORT_SUP */
565 return VINF_SUCCESS;
566# endif /* VBOX_WITH_WIN_PARPORT_SUP */
567}
568
569/* -=-=-=-=- IBase -=-=-=-=- */
570
571/**
572 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
573 */
574static DECLCALLBACK(void *) drvHostParallelQueryInterface(PPDMIBASE pInterface, const char *pszIID)
575{
576 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
577 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
578
579 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
580 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTPARALLELCONNECTOR, &pThis->CTX_SUFF(IHostParallelConnector));
581 return NULL;
582}
583
584
585/* -=-=-=-=- IHostDeviceConnector -=-=-=-=- */
586
587/**
588 * @interface_method_impl{PDMIHOSTPARALLELCONNECTOR,pfnWrite}
589 */
590static DECLCALLBACK(int) drvHostParallelWrite(PPDMIHOSTPARALLELCONNECTOR pInterface, const void *pvBuf, size_t cbWrite, PDMPARALLELPORTMODE enmMode)
591{
592 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
593 //PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
594 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector));
595 int rc = VINF_SUCCESS;
596 int rcLnx = 0;
597
598 LogFlowFunc(("pvBuf=%#p cbWrite=%d\n", pvBuf, cbWrite));
599
600 rc = drvHostParallelSetMode(pThis, enmMode);
601 if (RT_FAILURE(rc))
602 return rc;
603# ifndef VBOX_WITH_WIN_PARPORT_SUP
604 if (enmMode == PDM_PARALLEL_PORT_MODE_SPP)
605 {
606 /* Set the data lines directly. */
607 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPWDATA, pvBuf);
608 }
609 else
610 {
611 /* Use write interface. */
612 rcLnx = write(RTFileToNative(pThis->hFileDevice), pvBuf, cbWrite);
613 }
614 if (RT_UNLIKELY(rcLnx < 0))
615 rc = RTErrConvertFromErrno(errno);
616# else /* VBOX_WITH_WIN_PARPORT_SUP */
617 if (pThis->fParportAvail)
618 {
619 for (size_t i = 0; i < cbWrite; i++)
620 {
621 uint64_t u64Data = (uint8_t) *((uint8_t *)(pvBuf) + i);
622 LogFlowFunc(("calling R0 to write to parallel port, data=%#x\n", u64Data));
623 rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_WRITE, u64Data);
624 AssertRC(rc);
625 }
626 }
627# endif /* VBOX_WITH_WIN_PARPORT_SUP */
628 return rc;
629}
630
631/**
632 * @interface_method_impl{PDMIHOSTPARALLELCONNECTOR,pfnRead}
633 */
634static DECLCALLBACK(int) drvHostParallelRead(PPDMIHOSTPARALLELCONNECTOR pInterface, void *pvBuf, size_t cbRead, PDMPARALLELPORTMODE enmMode)
635{
636 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector));
637 int rc = VINF_SUCCESS;
638
639# ifndef VBOX_WITH_WIN_PARPORT_SUP
640 int rcLnx = 0;
641 LogFlowFunc(("pvBuf=%#p cbRead=%d\n", pvBuf, cbRead));
642
643 rc = drvHostParallelSetMode(pThis, enmMode);
644 if (RT_FAILURE(rc))
645 return rc;
646
647 if (enmMode == PDM_PARALLEL_PORT_MODE_SPP)
648 {
649 /* Set the data lines directly. */
650 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPWDATA, pvBuf);
651 }
652 else
653 {
654 /* Use write interface. */
655 rcLnx = read(RTFileToNative(pThis->hFileDevice), pvBuf, cbRead);
656 }
657 if (RT_UNLIKELY(rcLnx < 0))
658 rc = RTErrConvertFromErrno(errno);
659# else /* VBOX_WITH_WIN_PARPORT_SUP */
660 if (pThis->fParportAvail)
661 {
662 *((uint8_t*)(pvBuf)) = 0; /* Initialize the buffer. */
663 for (size_t i = 0; i < cbRead; i++)
664 {
665 LogFlowFunc(("calling R0 to read from parallel port\n"));
666 int rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READ, 0);
667 AssertRC(rc);
668 *((uint8_t *)pvBuf + i) = (uint8_t)pThis->u8ReadIn;
669 }
670 }
671# endif /* VBOX_WITH_WIN_PARPORT_SUP */
672 return rc;
673}
674
675/**
676 * @interface_method_impl{PDMIHOSTPARALLELCONNECTOR,pfnSetPortDirection}
677 */
678static DECLCALLBACK(int) drvHostParallelSetPortDirection(PPDMIHOSTPARALLELCONNECTOR pInterface, bool fForward)
679{
680 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector));
681 int rc = VINF_SUCCESS;
682 int iMode = 0;
683 if (!fForward)
684 iMode = 1;
685# ifndef VBOX_WITH_WIN_PARPORT_SUP
686 int rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPDATADIR, &iMode);
687 if (RT_UNLIKELY(rcLnx < 0))
688 rc = RTErrConvertFromErrno(errno);
689
690# else /* VBOX_WITH_WIN_PARPORT_SUP */
691 uint64_t u64Data;
692 u64Data = (uint8_t)iMode;
693 if (pThis->fParportAvail)
694 {
695 LogFlowFunc(("calling R0 to write CTRL, data=%#x\n", u64Data));
696 rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_SETPORTDIRECTION, u64Data);
697 AssertRC(rc);
698 }
699# endif /* VBOX_WITH_WIN_PARPORT_SUP */
700 return rc;
701}
702
703/**
704 * @interface_method_impl{PDMIHOSTPARALLELCONNECTOR,pfnWriteControl}
705 */
706static DECLCALLBACK(int) drvHostParallelWriteControl(PPDMIHOSTPARALLELCONNECTOR pInterface, uint8_t fReg)
707{
708 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector));
709 int rc = VINF_SUCCESS;
710 int rcLnx = 0;
711
712 LogFlowFunc(("fReg=%#x\n", fReg));
713# ifndef VBOX_WITH_WIN_PARPORT_SUP
714 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPWCONTROL, &fReg);
715 if (RT_UNLIKELY(rcLnx < 0))
716 rc = RTErrConvertFromErrno(errno);
717# else /* VBOX_WITH_WIN_PARPORT_SUP */
718 uint64_t u64Data;
719 u64Data = (uint8_t)fReg;
720 if (pThis->fParportAvail)
721 {
722 LogFlowFunc(("calling R0 to write CTRL, data=%#x\n", u64Data));
723 rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_WRITECONTROL, u64Data);
724 AssertRC(rc);
725 }
726# endif /* VBOX_WITH_WIN_PARPORT_SUP */
727 return rc;
728}
729
730
731/**
732 * @interface_method_impl{PDMIHOSTPARALLELCONNECTOR,pfnReadControl}
733 */
734static DECLCALLBACK(int) drvHostParallelReadControl(PPDMIHOSTPARALLELCONNECTOR pInterface, uint8_t *pfReg)
735{
736 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector));
737 int rc = VINF_SUCCESS;
738 int rcLnx = 0;
739 uint8_t fReg = 0;
740
741# ifndef VBOX_WITH_WIN_PARPORT_SUP
742 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPRCONTROL, &fReg);
743 if (RT_UNLIKELY(rcLnx < 0))
744 rc = RTErrConvertFromErrno(errno);
745 else
746 {
747 LogFlowFunc(("fReg=%#x\n", fReg));
748 *pfReg = fReg;
749 }
750# else /* VBOX_WITH_WIN_PARPORT_SUP */
751 *pfReg = 0; /* Initialize the buffer*/
752 if (pThis->fParportAvail)
753 {
754 LogFlowFunc(("calling R0 to read control from parallel port\n"));
755 rc = PDMDrvHlpCallR0(pThis-> CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READCONTROL, 0);
756 AssertRC(rc);
757 *pfReg = pThis->u8ReadInControl;
758 }
759# endif /* VBOX_WITH_WIN_PARPORT_SUP */
760 return rc;
761}
762
763/**
764 * @interface_method_impl{PDMIHOSTPARALLELCONNECTOR,pfnReadStatus}
765 */
766static DECLCALLBACK(int) drvHostParallelReadStatus(PPDMIHOSTPARALLELCONNECTOR pInterface, uint8_t *pfReg)
767{
768 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector));
769 int rc = VINF_SUCCESS;
770 int rcLnx = 0;
771 uint8_t fReg = 0;
772# ifndef VBOX_WITH_WIN_PARPORT_SUP
773 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPRSTATUS, &fReg);
774 if (RT_UNLIKELY(rcLnx < 0))
775 rc = RTErrConvertFromErrno(errno);
776 else
777 {
778 LogFlowFunc(("fReg=%#x\n", fReg));
779 *pfReg = fReg;
780 }
781# else /* VBOX_WITH_WIN_PARPORT_SUP */
782 *pfReg = 0; /* Intialize the buffer. */
783 if (pThis->fParportAvail)
784 {
785 LogFlowFunc(("calling R0 to read status from parallel port\n"));
786 rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READSTATUS, 0);
787 AssertRC(rc);
788 *pfReg = pThis->u8ReadInStatus;
789 }
790# endif /* VBOX_WITH_WIN_PARPORT_SUP */
791 return rc;
792}
793
794# ifndef VBOX_WITH_WIN_PARPORT_SUP
795
796static DECLCALLBACK(int) drvHostParallelMonitorThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
797{
798 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
799 struct pollfd aFDs[2];
800
801 /*
802 * We can wait for interrupts using poll on linux hosts.
803 */
804 while (pThread->enmState == PDMTHREADSTATE_RUNNING)
805 {
806 int rc;
807
808 aFDs[0].fd = RTFileToNative(pThis->hFileDevice);
809 aFDs[0].events = POLLIN;
810 aFDs[0].revents = 0;
811 aFDs[1].fd = RTPipeToNative(pThis->hWakeupPipeR);
812 aFDs[1].events = POLLIN | POLLERR | POLLHUP;
813 aFDs[1].revents = 0;
814 rc = poll(aFDs, RT_ELEMENTS(aFDs), -1);
815 if (rc < 0)
816 {
817 AssertMsgFailed(("poll failed with rc=%d\n", RTErrConvertFromErrno(errno)));
818 return RTErrConvertFromErrno(errno);
819 }
820
821 if (pThread->enmState != PDMTHREADSTATE_RUNNING)
822 break;
823 if (rc > 0 && aFDs[1].revents)
824 {
825 if (aFDs[1].revents & (POLLHUP | POLLERR | POLLNVAL))
826 break;
827 /* notification to terminate -- drain the pipe */
828 char ch;
829 size_t cbRead;
830 RTPipeRead(pThis->hWakeupPipeR, &ch, 1, &cbRead);
831 continue;
832 }
833
834 /* Interrupt occurred. */
835 rc = pThis->pDrvHostParallelPort->pfnNotifyInterrupt(pThis->pDrvHostParallelPort);
836 AssertRC(rc);
837 }
838
839 return VINF_SUCCESS;
840}
841
842/**
843 * Unblock the monitor thread so it can respond to a state change.
844 *
845 * @returns a VBox status code.
846 * @param pDrvIns The driver instance.
847 * @param pThread The send thread.
848 */
849static DECLCALLBACK(int) drvHostParallelWakeupMonitorThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
850{
851 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
852 size_t cbIgnored;
853 return RTPipeWrite(pThis->hWakeupPipeW, "", 1, &cbIgnored);
854}
855
856# endif /* VBOX_WITH_WIN_PARPORT_SUP */
857
858/**
859 * Destruct a host parallel driver instance.
860 *
861 * Most VM resources are freed by the VM. This callback is provided so that
862 * any non-VM resources can be freed correctly.
863 *
864 * @param pDrvIns The driver instance data.
865 */
866static DECLCALLBACK(void) drvHostParallelDestruct(PPDMDRVINS pDrvIns)
867{
868 int rc;
869 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
870 LogFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
871 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
872
873#ifndef VBOX_WITH_WIN_PARPORT_SUP
874 if (pThis->hFileDevice != NIL_RTFILE)
875 ioctl(RTFileToNative(pThis->hFileDevice), PPRELEASE);
876
877 if (pThis->hWakeupPipeW != NIL_RTPIPE)
878 {
879 rc = RTPipeClose(pThis->hWakeupPipeW); AssertRC(rc);
880 pThis->hWakeupPipeW = NIL_RTPIPE;
881 }
882
883 if (pThis->hWakeupPipeR != NIL_RTPIPE)
884 {
885 rc = RTPipeClose(pThis->hWakeupPipeR); AssertRC(rc);
886 pThis->hWakeupPipeR = NIL_RTPIPE;
887 }
888
889 if (pThis->hFileDevice != NIL_RTFILE)
890 {
891 rc = RTFileClose(pThis->hFileDevice); AssertRC(rc);
892 pThis->hFileDevice = NIL_RTFILE;
893 }
894
895 if (pThis->pszDevicePath)
896 {
897 MMR3HeapFree(pThis->pszDevicePath);
898 pThis->pszDevicePath = NULL;
899 }
900#else /* VBOX_WITH_WIN_PARPORT_SUP */
901 if (pThis->hWinFileDevice != NIL_RTFILE)
902 {
903 rc = RTFileClose(pThis->hWinFileDevice); AssertRC(rc);
904 pThis->hWinFileDevice = NIL_RTFILE;
905 }
906#endif /* VBOX_WITH_WIN_PARPORT_SUP */
907}
908
909/**
910 * Construct a host parallel driver instance.
911 *
912 * @copydoc FNPDMDRVCONSTRUCT
913 */
914static DECLCALLBACK(int) drvHostParallelConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
915{
916 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
917 LogFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
918
919 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
920
921 /*
922 * Init basic data members and interfaces.
923 *
924 * Must be done before returning any failure because we've got a destructor.
925 */
926 pThis->hFileDevice = NIL_RTFILE;
927#ifndef VBOX_WITH_WIN_PARPORT_SUP
928 pThis->hWakeupPipeR = NIL_RTPIPE;
929 pThis->hWakeupPipeW = NIL_RTPIPE;
930#else
931 pThis->hWinFileDevice = NIL_RTFILE;
932#endif
933
934 pThis->pDrvInsR3 = pDrvIns;
935#ifdef VBOX_WITH_DRVINTNET_IN_R0
936 pThis->pDrvInsR0 = PDMDRVINS_2_R0PTR(pDrvIns);
937#endif
938
939 /* IBase. */
940 pDrvIns->IBase.pfnQueryInterface = drvHostParallelQueryInterface;
941 /* IHostParallelConnector. */
942 pThis->IHostParallelConnectorR3.pfnWrite = drvHostParallelWrite;
943 pThis->IHostParallelConnectorR3.pfnRead = drvHostParallelRead;
944 pThis->IHostParallelConnectorR3.pfnSetPortDirection = drvHostParallelSetPortDirection;
945 pThis->IHostParallelConnectorR3.pfnWriteControl = drvHostParallelWriteControl;
946 pThis->IHostParallelConnectorR3.pfnReadControl = drvHostParallelReadControl;
947 pThis->IHostParallelConnectorR3.pfnReadStatus = drvHostParallelReadStatus;
948
949 /*
950 * Validate the config.
951 */
952 if (!CFGMR3AreValuesValid(pCfg, "DevicePath\0"))
953 return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
954 N_("Unknown host parallel configuration option, only supports DevicePath"));
955
956 /*
957 * Query configuration.
958 */
959 /* Device */
960 int rc = CFGMR3QueryStringAlloc(pCfg, "DevicePath", &pThis->pszDevicePath);
961 if (RT_FAILURE(rc))
962 {
963 AssertMsgFailed(("Configuration error: query for \"DevicePath\" string returned %Rra.\n", rc));
964 return rc;
965 }
966
967 /*
968 * Open the device
969 */
970 rc = RTFileOpen(&pThis->hFileDevice, pThis->pszDevicePath, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
971 if (RT_FAILURE(rc))
972 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("Parallel#%d could not open '%s'"),
973 pDrvIns->iInstance, pThis->pszDevicePath);
974
975#ifndef VBOX_WITH_WIN_PARPORT_SUP
976 /*
977 * Try to get exclusive access to parallel port
978 */
979 rc = ioctl(RTFileToNative(pThis->hFileDevice), PPEXCL);
980 if (rc < 0)
981 return PDMDrvHlpVMSetError(pDrvIns, RTErrConvertFromErrno(errno), RT_SRC_POS,
982 N_("Parallel#%d could not get exclusive access for parallel port '%s'"
983 "Be sure that no other process or driver accesses this port"),
984 pDrvIns->iInstance, pThis->pszDevicePath);
985
986 /*
987 * Claim the parallel port
988 */
989 rc = ioctl(RTFileToNative(pThis->hFileDevice), PPCLAIM);
990 if (rc < 0)
991 return PDMDrvHlpVMSetError(pDrvIns, RTErrConvertFromErrno(errno), RT_SRC_POS,
992 N_("Parallel#%d could not claim parallel port '%s'"
993 "Be sure that no other process or driver accesses this port"),
994 pDrvIns->iInstance, pThis->pszDevicePath);
995
996 /*
997 * Get the IHostParallelPort interface of the above driver/device.
998 */
999 pThis->pDrvHostParallelPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHOSTPARALLELPORT);
1000 if (!pThis->pDrvHostParallelPort)
1001 return PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE, RT_SRC_POS, N_("Parallel#%d has no parallel port interface above"),
1002 pDrvIns->iInstance);
1003
1004 /*
1005 * Create wakeup pipe.
1006 */
1007 rc = RTPipeCreate(&pThis->hWakeupPipeR, &pThis->hWakeupPipeW, 0 /*fFlags*/);
1008 AssertRCReturn(rc, rc);
1009
1010 /*
1011 * Start in SPP mode.
1012 */
1013 pThis->enmModeCur = PDM_PARALLEL_PORT_MODE_INVALID;
1014 rc = drvHostParallelSetMode(pThis, PDM_PARALLEL_PORT_MODE_SPP);
1015 if (RT_FAILURE(rc))
1016 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostParallel#%d cannot change mode of parallel mode to SPP"), pDrvIns->iInstance);
1017
1018 /*
1019 * Start waiting for interrupts.
1020 */
1021 rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pMonitorThread, pThis, drvHostParallelMonitorThread, drvHostParallelWakeupMonitorThread, 0,
1022 RTTHREADTYPE_IO, "ParMon");
1023 if (RT_FAILURE(rc))
1024 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostParallel#%d cannot create monitor thread"), pDrvIns->iInstance);
1025
1026#else /* VBOX_WITH_WIN_PARPORT_SUP */
1027 pThis->fParportAvail = false;
1028 pThis->u32LptAddr = 0;
1029 pThis->u32LptAddrControl = 0;
1030 pThis->u32LptAddrStatus = 0;
1031 rc = drvWinHostGetparportAddr(pThis);
1032
1033 /* If we have the char port availabe use it , else I am not getting exclusive access to parallel port.
1034 Read and write will be done only if addresses are available
1035 */
1036 if (pThis->szParportName)
1037 {
1038 rc = RTFileOpen(&pThis->hWinFileDevice, (char *)pThis->szParportName,
1039 RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
1040 }
1041#endif
1042 return VINF_SUCCESS;
1043}
1044
1045
1046/**
1047 * Char driver registration record.
1048 */
1049const PDMDRVREG g_DrvHostParallel =
1050{
1051 /* u32Version */
1052 PDM_DRVREG_VERSION,
1053 /* szName */
1054 "HostParallel",
1055 /* szRCMod */
1056 "",
1057 /* szR0Mod */
1058 "VBoxDDR0.r0",
1059 /* pszDescription */
1060 "Parallel host driver.",
1061 /* fFlags */
1062# if defined(VBOX_WITH_WIN_PARPORT_SUP)
1063 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DRVREG_FLAGS_R0,
1064# else
1065 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
1066# endif
1067 /* fClass. */
1068 PDM_DRVREG_CLASS_CHAR,
1069 /* cMaxInstances */
1070 ~0U,
1071 /* cbInstance */
1072 sizeof(DRVHOSTPARALLEL),
1073 /* pfnConstruct */
1074 drvHostParallelConstruct,
1075 /* pfnDestruct */
1076 drvHostParallelDestruct,
1077 /* pfnRelocate */
1078 NULL,
1079 /* pfnIOCtl */
1080 NULL,
1081 /* pfnPowerOn */
1082 NULL,
1083 /* pfnReset */
1084 NULL,
1085 /* pfnSuspend */
1086 NULL,
1087 /* pfnResume */
1088 NULL,
1089 /* pfnAttach */
1090 NULL,
1091 /* pfnDetach */
1092 NULL,
1093 /* pfnPowerOff */
1094 NULL,
1095 /* pfnSoftReset */
1096 NULL,
1097 /* u32EndVersion */
1098 PDM_DRVREG_VERSION
1099};
1100#endif /*IN_RING3*/
1101
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette