VirtualBox

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

Last change on this file since 43383 was 43383, checked in by vboxsync, 12 years ago

Devices/Parallel: Added more debug statements for enhanced logging.. Need to give debug build to user for debugging. Will revert the changes soon.

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

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