/* This software is covered by the GNU GENERAL PUBLIC LICENSE (GPL). */
/* Any Device - Driver - Linux */
/* $Workfile: kernel_2_6.h $ */
/* $Revision: 3 $ */
/* $Date: 10/27/07 10:36a $ */
/*
*	Provide special handling for things specific to the 2.6 kernel.
*/
/* $Log: /NEW SOURCESAFE DATABASE/SDK/PLX/gsc/common/driver/linux/kernel_2_6.h $
 * 
 * 3     10/27/07 10:36a Dnewbold
 * Additional driver porting updates.
 *
 * 2     3/29/07 2:47p Dnewbold
 *
 * 1     5/10/06 1:01p Dnewbold
*/

#ifndef __KERNEL_2_6_H__
#define __KERNEL_2_6_H__

#if	(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) && \
	(LINUX_VERSION_CODE <  KERNEL_VERSION(2,7,0))

#include <linux/moduleparam.h>
#include <linux/slab.h>



/* #defines	**************************************************************/

#define	CURRENT_PROCESS_ID			current->tgid
#define	DMA_SGL_SUPPORT_FIELD		dev_dma_sgl_2_6_t*	iobuf;
#define	EVENT_RESUME_IRQ(q,c)		c = 1; wake_up_interruptible(q)
#define	EVENT_WAIT_IRQ_TO(q,c,t)	\
	(c) = 0; wait_event_interruptible_timeout((q)[0],(c),(t))
#define	GET_PAGE(page)				get_page((page))
#define	KILL_FASYNC(q,s,b)			kill_fasync(&(q),(s),(b))
#define	KMALLOC_LIMIT				(128L * 1024)
#undef	MOD_DEC_USE_COUNT
#define	MOD_DEC_USE_COUNT
#undef	MOD_INC_USE_COUNT
#define	MOD_INC_USE_COUNT
#define	NUM_SGL_PAGES				((8L * 1024L * 1024L / PAGE_SIZE) + 1)
#define	PAGE_RESERVE(vpa)			SetPageReserved(virt_to_page((vpa)))
#define	PAGE_UNRESERVE(vpa)			ClearPageReserved(virt_to_page((vpa)))

#define	PCI_DEVICE_LOOP(p)	\
	for ((p) = NULL; ((p) = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, (p))); )

#define	PCI_ENABLE_DEVICE(pci)		pci_enable_device(pci)
#define	REGION_IO_CHECK(a,s)		0
#define	REGION_IO_RELEASE(a,s)		release_region(a,s)
#define	REGION_IO_REQUEST(a,s,n)	request_region(a,s,n)
#define	REGION_MEM_CHECK(a,s)		check_mem_region(a,s)
#define	REGION_MEM_RELEASE(a,s)		release_mem_region(a,s)
#define	REGION_MEM_REQUEST(a,s,n)	request_mem_region(a,s,n)
#define	SET_CURRENT_STATE(s)		current->state = (s)
#define	SET_MODULE_OWNER(p)
#define	VADDR_T						void*
#define	VIRT_TO_PAGE(p)				virt_to_page((p))
#define	VM_OFFSET_BYTES(vma)		((vma)->vm_pgoff * PAGE_SIZE)
#define	VM_OPS_UNMAP(vmo,fun)
#define	WAIT_QUEUE_ENTRY_INIT(w,c)	init_waitqueue_entry((w),(c))
#define	WAIT_QUEUE_ENTRY_T			wait_queue_t
#define	WAIT_QUEUE_HEAD_INIT(q)		init_waitqueue_head((q))
#define	WAIT_QUEUE_HEAD_T			wait_queue_head_t

#if	(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11))
	#define	REMAP_PAGE_RANGE(vma,vm_adrs,ph_adrs,size,prot)		\
			remap_pfn_range( vma,vm_adrs,ph_adrs >> PAGE_SHIFT,	\
								BYTES_TO_PAGE_BYTES((size)),prot)
#else
	#define	REMAP_PAGE_RANGE(v,f,t,s,p)	remap_page_range(v,f,t,s,p)
#endif

#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,19))
	#define	IRQ_REQUEST(dv,fnc)		request_irq((dv)->pci->irq,				\
												(fnc),						\
												SA_SHIRQ,					\
												DRV_DEV_DEVICE_NAME_LOWER,	\
												(dv))
#else
	#define	IRQ_REQUEST(dv,fnc)		request_irq((dv)->pci->irq,				\
												(fnc),						\
												IRQF_SHARED,				\
												DRV_DEV_DEVICE_NAME_LOWER,	\
												(dv))
#endif

#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18))
	#define	ISR_ARG3				, struct pt_regs* regs
#else
	#define	ISR_ARG3
#endif

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26))
	#define	MMAP_FAULT_INCLUDE		1
	#define	MMAP_NOPAGE_INCLUDE		0
	#define	PROC_GET_INFO(pro,fun)
	#define	VM_OPS_FAULT(vmo,fun)	(vmo).fault = (fun)
	#define	VM_OPS_NOPAGE(vmo,fun)
#else
	#define	MMAP_FAULT_INCLUDE		0
	#define	MMAP_NOPAGE_INCLUDE		1
	#define	PROC_GET_INFO(pro,fun)	(pro)->get_info = (fun)
	#define	VM_OPS_FAULT(vmo,fun)
	#define	VM_OPS_NOPAGE(vmo,fun)	(vmo).nopage = (fun)
#endif



/* typedefs	******************************************************************/

typedef struct
{
	u32				flags;		// from the transfer
	int				offset;		// offset in first page
	int				nr_pages;	// number of user pages to be mapped
	int				mapped;		// number of pages actually mapped
	u32				length;		// overall size in bytes
	struct page*	maplist[NUM_SGL_PAGES];
} dev_dma_sgl_2_6_t;



/* prototypes	**************************************************************/

irqreturn_t		irq_isr(int irq, void* dev_id   ISR_ARG3);

#if MMAP_FAULT_INCLUDE
int				mmap_fault(struct vm_area_struct* vma, struct vm_fault* vmf);
#endif

#if MMAP_NOPAGE_INCLUDE
struct page*	mmap_nopage(struct vm_area_struct*	vma,
							unsigned long			address,
							int*					type);
#endif

int				proc_get_info(	char*	page,
								char**	start,
								off_t	offset,
								int		count);



#endif
#endif
