	.title	CDDEFIN
	.sbttl	Disk Cache Driver Rev 2 Symbolic Definitions
	.ident	/071789/
;
;+
;*****
;
;  CDDEFIN.MAR - Defines all symbolic offsets for data structures required
;	by the block-set associative disk data caching driver, CDDRIVER2.
;
;-
;*****
;
;	Paul Sorenson
;	AEP/Engineering Computer Support Center
;	Columbus, OH  43215
;
;*****
;
	.page
	.SBTTL	Cache Driver Specific I/O Function Codes
;
; ***
;

	.MACRO	CD$IODEF,A
	
	$IODEF	A			; standard I/O function definitions
	$DEFINI	IO,A
;
; *** Declare IO$_READxBLK function modifiers...must not conflict with
;	IO$V_TIMED !!
;
	$VIELD	IO,IO$V_FMODIFIERS,<-
		<CD_RRD,,M>>		; record all read operations

;
; *** Declare IO$_SETMODE function modifiers
;
	$VIELD	IO,IO$V_FMODIFIERS,<-
	- ; *** Major SETMODE modifiers; mutually exclusive
		<CD_STARTUP,,M>,-	; startup caching
		<CD_SHUTDOWN,,M>,-	; shutdown caching
		<CD_EXTEND,,M>,-	; extend size of cache
		<CD_PURGE,,M>,-		; purge contents of cache
		<CD_RESERVED1,,M>,-	;  (currently undefined)
		<CD_RESERVED2,,M>,-	;  (currently undefined)
	- ; *** Common modifier for any major modifier
		<CD_ZERO,,M>,-		; zero cache statistical counters
	- ; *** Declare IO$M_STARTUP modifiers
		<CD_PAGSWAPIO,,M>,-	; allow caching of page/swap I/Os
		<CD_LOAD,,M>,-		; load cache contents on write
		<CD_FLUSH,,M>>		; invalidate cache contents on write

$EQU	IO$M_CD_SETMODES	-	; mask for major SETMODE modifiers
		<IO$M_CD_STARTUP!IO$M_CD_SHUTDOWN!-
		 IO$M_CD_EXTEND!IO$M_CD_PURGE>

;
; *** Declare IO$_SENSEMODE function modifiers
;
	$VIELD	IO,IO$V_FMODIFIERS,<-
		<CD_GETINFO,,M>>	; get information on cache

	$DEFEND	IO

	.MACRO	CD$IODEF,B
	.ENDM
	.ENDM

;
	.page
	.SBTTL	Pending I/O Identification Block Definition
;
; *** Pending I/O Identification Block (PIB) structure saves information
;	regarding I/O requests handled by the cache driver that will
;	be returned to the cache driver for further processing at some
;	future time.  PIBs are linked to the "PENDQFL" queue list
;	while the operation is pending and are released to the
;	"free" list headed at "FREEQFL".  The free and pending queue list
;	heads are part of the driver's local data space and link PIBs
;	for all units of the driver.  PIBs are allocated from
;	non-paged system pool (an IRP) if the free list is empty.
;
	.MACRO	CD$PIBDEF,A

	$DEFINI	PIB,A

$DEF	PIB$L_PENDQFL			; forward link
			.BLKL	1
$DEF	PIB$L_PENDQBL			; backward link
			.BLKL	1
$DEF	PIB$L_IRP			; address of IRP associated with request
			.BLKL	1
$DEF	PIB$L_PID			; saved PID from IRP
			.BLKL	1
$DEF	PIB$L_UCB			; address of cache driver UCB
			.BLKL	1
$DEF	PIB$L_LBN			; starting LBN of data being transferred
			.BLKL	1
$DEF	PIB$K_LENGTH			; length of PIB structure

	$DEFEND	PIB


	.MACRO	CD$PIBDEF B
	.ENDM
	.ENDM
;
	.page
	.SBTTL	Cache Tag Block
;
; *** Tag block structure saves information on the logical block
;	number associated with each block of data cached and the
;	page frame number of the memory page containing the cached data.
;	Tags are allocated from non-paged pool via the IO$V_CD_STARTUP
;	and/or IO$V_CD_EXTEND functions.
;
	.MACRO	CD$TAGDEF,A

	$DEFINI	TAG,A

$DEF	TAG$L_LBN			; full 32-bit LBN of data cached
			.BLKL	1
$DEF	TAG$L_PFN			; control/mapping info for cached data
			.BLKL	1

	$VIELD	TAG,0,<-		; bit fields within PFN
		<PFN,24,M>,-		; mask for page frame number
		<REREAD,,M>,-		; bit set on subsequent read of data
		<WRLOAD,,M>,-		; bit set when data loaded by write QIO
		<VALID,,M>,-		; bit set when PFN contains valid data
		<REFCNT,5,M>>		; mask for reference count field
					;  (balance of bits from VALID to 31)

$EQU	TAG$K_REFCNT TAG$M_VALID*2	; value to subtract from PFN "REFCNT"
					;  to track least recently used tag

$DEF	TAG$K_LENGTH			; size of each cache "tag"

	$DEFEND	TAG


	.MACRO	CD$TAGDEF B
	.ENDM
	.ENDM

;
	.page
	.sbttl	Cache Driver UCB Extension Definition
;
; *** Unit Control Block (UCB) extension fields for CDDRIVER.
;


	.MACRO	CD$UCBDEF,A

	$UCBDEF	A			; Unit control block definitions
	$TQEDEF	A			; Timer queue element definitions
	$FKBDEF	A			; Fork block definitions
	$DEFINI	UCB,A			; Start of UCB extension definitions

$EQU	CD_CACHESIZE 32767		; Absolute max # pages allowed in cache
					;  (no real limit imposed by driver)
;
; *** Bit positions for device-dependent status in UCB$L_DEVDEPEND
;

	$VIELD	UCB,0,<-		; Device status
		<CD_FLUSH,,M>,-		; set to invalidate cache on write
		<CD_LOAD,,M>,-		; set to enable loading cache on write
		<CD_PAGSWAPIO,,M>,-	; set to enable caching of page/swap I/O
		<CD_RRD,,M>,-		; set to record read QIOs (archaic)
		<CD_TIMED,,M>,-		; set when read timeout timer active
		<CD_ALLOC,,M>,-		; set when memory allocated to cache
		<CD_ACTIVE,,M>>		; set when caching active

$EQU	UCB$M_CD_DEFAULT 0		; default value for DEVDEPEND

;
; *** Second device dependent status definition
;

$EQU	UCB$L_CD_DSKUCB	UCB$L_DEVDEPND2	; UCB address of disk being cached

	.=UCB$K_LENGTH			; Position at end of simple UCB
;
; *** Timer queue element to support IO$_READxBLK!IO$M_TIMED QIO function
;
$DEF	UCB$T_CD_TQE
			.BLKB	TQE$K_LENGTH
;
; *** Alternate fork block for execution @ IPL$_QUEUEAST
;
$DEF	UCB$Q_CD_FLBN			; Fork save area for LBN/block count
			.BLKL	2
$DEF	UCB$T_CD_FKB			; Fork block
			.BLKB	FKB$K_LENGTH
;
$DEF	UCB$L_CD_TAGSIZE		; size of cache tag block
			.BLKL	1
$DEF	UCB$L_CD_TAGADDR		; address of cache tag block
			.BLKL	1
$DEF	UCB$L_CD_CSPTE			; address of system page table entry
			.BLKL	1	;  reserved to map cache
$DEF	UCB$L_CD_CSVA			; system virtual address to reference
			.BLKL	1	;  when reading/writing cache buffer
$DEF	UCB$L_CD_USPTE			; address of first of 2 consecutive 
			.BLKL	1	;  system page table entries reserved
					;   to map user's buffer
$DEF	UCB$L_CD_USVA			; system virtual address to reference
			.BLKL	1	;  when reading/writing user's buffer
$DEF	UCB$L_CD_DSKSTARTIO		; disk driver's start_io entry point
			.BLKL	1
$DEF	UCB$L_CD_DSKDDT			; DDT addr of physical disk being cached
			.BLKL	1
$DEF	UCB$L_CD_SVAPTE			; system virtual address of page table
			.BLKL	1	;  entry defining VA of user's buffer
$DEF	UCB$W_CD_BOFF			; byte offset into page for user's
			.BLKW	2	;  buffer; round to longword

;
; *** Start of cache information & statistic counters...these must be long
;	word aligned
;
$DEF	UCB$T_CD_INFO
$DEF	UCB$T_CD_NAME			; generic device name of cached disk
			.BLKB	16
$DEF	UCB$W_CD_UNIT			; physical unit number of cached disk
			.BLKW	1
$DEF	UCB$W_CD_RESERVED		;  (currently undefined)
			.BLKW	1
$DEF	UCB$L_CD_SETSIZE		; # blocks/set
			.BLKL	1
$DEF	UCB$L_CD_SETCOUNT		; # sets in cache
			.BLKL	1
$DEF	UCB$L_CD_CACHESIZE		; size of cache in blocks (pages)
			.BLKL	1	;  (SETSIZE*SETCOUNT)
$DEF	UCB$T_CD_STATS
$DEF   	UCB$L_CD_RDCNT			; number of read operations processed
			.BLKL	1
$DEF	UCB$L_CD_RDBLK			; total number of blocks read
			.BLKL	1
$DEF	UCB$L_CD_RDLOAD			; number of blocks loaded by read QIO
			.BLKL	1
$DEF	UCB$L_CD_RDONCE			; number of blocks loaded by read
			.BLKL	1	;  that were never re-read
$DEF	UCB$L_CD_RDHIT			; number of blocks read from cache
			.BLKL	1
$DEF	UCB$L_CD_WRCNT			; number of write operations processed
 			.BLKL	1
$DEF	UCB$L_CD_WRBLK			; total number of blocks written
			.BLKL	1
$DEF	UCB$L_CD_WRLOAD			; number of blocks loaded by write QIO
			.BLKL	1
$DEF	UCB$L_CD_WRONCE			; number of blocks loaded by write
			.BLKL	1	;  that were never re-read
$DEF	UCB$K_CD_LENGTH			; Length of extended UCB

	$DEFEND	UCB			; End of UCB definitions

	.MACRO	CD$UCBDEF B
	.ENDM
	.ENDM
;
	CD$IODEF	GLOBAL		; define I/O function codes globally
					;  when assembled separately

	.end
