/*++
*******************************************************************************
* Copyright (c) 1990-97 Digi International Inc., All Rights Reserved				*
* 																										*
* This software contains proprietary and confidential information of Digi		*
* International Inc.  By accepting transfer of this copy, Recipient agrees		*
* to retain this software in confidence, to prevent disclosure to others,		*
* and to make no use of this software other than that for which it was			*
* delivered.  This is an unpublished copyrighted work of Digi International	*
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly	*
* prohibited.																						*
* 																										*
* Restricted Rights Legend																		*
*																										*
* Use, duplication, or disclosure by the Government is subject to					*
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in			*
* Technical Data and Computer Software clause at DFARS 252.227-7031 or			*
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -				*
* Restricted Rights at 48 CFR 52.227-19, as applicable.								*
*																										*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343				*
*																										*
*******************************************************************************

Module Name:

   DigiKme.h

Abstract:

   This header contains constants and defines used to support KME on Windows NT.
	KME, in UNIX-speak is a Kernel Memory Editor - allowing a usermode application
	to read and write kernel memory, and is typically used while debugging/tuning
	drivers.  Digi extended KME to support Digi adapter memory, and ported the 
	whole idea to Windows NT.

Author:

	   Michael Zarns

Revision History:

--*/
#ifndef DIGIKME_H
#define DIGIKME_H

#ifdef _NTDDK_
#include <devioctl.h>		// Kernelmode drivers need this.  Resides in ddk.
#else
#include <winioctl.h>		// Usermode apps need this.  Resides in msdev\include.
#endif

#include "DgDevice.h"

// Define RSVD.  RSVD is used in struct definitions to identify fields which
// are reserved for the Driver.  These fields should be initialized to zero 
// before passing the request to the driver.
#define RSVD


///////////////////////////////////////////////////////////////////////////////
//
// KME API IOCTLs
//
// Note: the KME file device (FILE_DEVICE_KME) is defined in DgDevice.h, a
// common header shared among many Digi drivers.  It's definition there allows
// us to guarantee that device id's don't overlap.

#define IOCTL_KME_READ		CTL_CODE(FILE_DEVICE_KME,		\
                           DIGI_FUNCTION_CODE_START,		\
                           METHOD_BUFFERED,					\
                           FILE_ANY_ACCESS)

#define IOCTL_KME_WRITE		CTL_CODE(FILE_DEVICE_KME,		\
                           DIGI_FUNCTION_CODE_START + 1,	\
                           METHOD_BUFFERED,					\
                           FILE_ANY_ACCESS)

#define IOCTL_KME_MAP		CTL_CODE(FILE_DEVICE_KME,		\
                           DIGI_FUNCTION_CODE_START + 2,	\
                           METHOD_BUFFERED,					\
                           FILE_ANY_ACCESS)

#define IOCTL_KME_UNMAP		CTL_CODE(FILE_DEVICE_KME,		\
                           DIGI_FUNCTION_CODE_START + 3,	\
                           METHOD_BUFFERED,					\
                           FILE_ANY_ACCESS)

///////////////////////////////////////////////////////////////////////////////
//
// KME IOCTL Structures
// 
// These structures define the data passed to and from a driver with KME support
// via the IOCTLs defined above.  Structure field labeling conventions: 
// 
//    IN:   Input to the request.
//    OUT:  Output returned when the request has completed.  Should be
//          initialized to zero.
//    RSVD: Reserved for use by the driver.  Must be initialized to zero.
//

typedef struct KME_READ 
{
	IN ULONG      Address;			// Address to be read
	IN ULONG      Length;			// Length of output buffer, and of requested read
	IN OUT PUCHAR pBuffer;			// Output buffer for read request
	IN ULONG      Flags;				// See Optional Flags below
	OUT ULONG     BytesRead;		// Output count of bytes read
	RSVD PUCHAR   pLockedBuffer;	// Driver private locked pointer to data buffer
} KME_READ, *PKME_READ;


typedef struct KME_WRITE
{
	IN ULONG      Address;			// Address to be written
	IN ULONG      Length;			// Length of buffer to write
	IN OUT PUCHAR pBuffer;			// Input buffer to write
	IN ULONG      Flags;				// See Optional Flags below
	OUT ULONG     BytesWritten;	// Output count of bytes written
	RSVD PUCHAR   pLockedBuffer;	// Driver private locked pointer to data buffer
} KME_WRITE, *PKME_WRITE;


typedef struct KME_MAP
{
	IN ULONG      Flags;				// See Optional Flags below
	OUT PVOID     pView;				// Pointer to view when mapped
	OUT ULONG     Length;			// Output count of bytes mapped
} KME_MAP, *PKME_MAP;

//
// Optional Flags Values
//

enum
{
	// ADAPTER_MEMORY is the default
	KME_FLAG_ADAPTER_MEMORY = 0,

	// Set HOST_MEMORY Flag to read or write NT kernel memory instead of adapter memory
	KME_FLAG_HOST_MEMORY,

	// Set PCI_INTERFACE_CHIP to access the adapter's pci interface chip address space
	KME_FLAG_PCI_INTERFACE_CHIP,

	// Set PCI_MEMORY_OTHER to access the "secondary" memory block presented by the pci
	// adapter.  This block is optional, and depends on the specific adapter 
	// implementation.  For Dense adapters, it is the DSP/GPP memory region.  For 
	// Clydesdale, it is the PLX runtime registers.
	KME_FLAG_PCI_MEMORY_OTHER
};

#endif
