xref: /titanic_44/usr/src/uts/common/sys/agp/agpgart_impl.h (revision 0035d21c77a24d02faf34c10aabc120ca692efb5)
17c478bd9Sstevel@tonic-gate /*
2*0035d21cSmiao chen - Sun Microsystems - Beijing China  * Copyright (c) 2009, Intel Corporation.
3*0035d21cSmiao chen - Sun Microsystems - Beijing China  * All Rights Reserved.
4*0035d21cSmiao chen - Sun Microsystems - Beijing China  */
5*0035d21cSmiao chen - Sun Microsystems - Beijing China 
6*0035d21cSmiao chen - Sun Microsystems - Beijing China /*
7*0035d21cSmiao chen - Sun Microsystems - Beijing China  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
87c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
97c478bd9Sstevel@tonic-gate  */
107c478bd9Sstevel@tonic-gate 
117c478bd9Sstevel@tonic-gate #ifndef	_SYS_AGPGART_IMPL_H
127c478bd9Sstevel@tonic-gate #define	_SYS_AGPGART_IMPL_H
137c478bd9Sstevel@tonic-gate 
147c478bd9Sstevel@tonic-gate #ifdef __cplusplus
157c478bd9Sstevel@tonic-gate extern "C" {
167c478bd9Sstevel@tonic-gate #endif
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate 
197c478bd9Sstevel@tonic-gate #ifdef _KERNEL
207c478bd9Sstevel@tonic-gate 
217c478bd9Sstevel@tonic-gate #define	AGPGART_MAX_INSTANCES	1
227c478bd9Sstevel@tonic-gate #define	AGP_MAXKEYS		256
237c478bd9Sstevel@tonic-gate #define	AGPGART_DEVNODE		"agpgart"
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate  * The values of type agp_arc_type_t are used as indexes into arc_name
277c478bd9Sstevel@tonic-gate  * in agp_kstat.c.
287c478bd9Sstevel@tonic-gate  * So if agp_arc_type_t's values are changed in the future, the content
297c478bd9Sstevel@tonic-gate  * of arc_name must be changed accordingly.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate enum agp_arc_type {
327c478bd9Sstevel@tonic-gate 	ARC_IGD810 = 0,
337c478bd9Sstevel@tonic-gate 	ARC_IGD830 = 1,
347c478bd9Sstevel@tonic-gate 	ARC_INTELAGP = 2,
357c478bd9Sstevel@tonic-gate 	ARC_AMD64AGP = 3,
367c478bd9Sstevel@tonic-gate 	ARC_UNKNOWN = 5
377c478bd9Sstevel@tonic-gate };
387c478bd9Sstevel@tonic-gate typedef enum agp_arc_type agp_arc_type_t;
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /* linked list structure of multiple agp gart devices access handles */
417c478bd9Sstevel@tonic-gate typedef struct	amd64_gart_dev_list {
427c478bd9Sstevel@tonic-gate 	ldi_handle_t			gart_devhdl;
437c478bd9Sstevel@tonic-gate 	struct	amd64_gart_dev_list	*next;
447c478bd9Sstevel@tonic-gate } amd64_gart_dev_list_t;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate typedef struct amd64_garts_dev {
477c478bd9Sstevel@tonic-gate 	int			gart_device_num;
487c478bd9Sstevel@tonic-gate 	amd64_gart_dev_list_t	*gart_dev_list_head;
497c478bd9Sstevel@tonic-gate } amd64_garts_dev_t;
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * AGP target and master device register their config space access
537c478bd9Sstevel@tonic-gate  * interface here.
547c478bd9Sstevel@tonic-gate  * In AMD64, gart_device_num is the number of hostbridge (device(1100, 1022))
557c478bd9Sstevel@tonic-gate  * refer to <<Bios and Kernel Developer's Guide for AMD athlon64 and operton>>
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate typedef struct agp_registered_dev {
587c478bd9Sstevel@tonic-gate 	amd64_garts_dev_t	agprd_cpugarts;
597c478bd9Sstevel@tonic-gate 	ldi_handle_t		agprd_targethdl;
607c478bd9Sstevel@tonic-gate 	ldi_handle_t		agprd_masterhdl;
617c478bd9Sstevel@tonic-gate 	agp_arc_type_t		agprd_arctype; /* system types */
627c478bd9Sstevel@tonic-gate } agp_registered_dev_t;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * If the OS have direct mapping support for mapping physical page frames
667c478bd9Sstevel@tonic-gate  * directly to user address, we use this struct for memory
677c478bd9Sstevel@tonic-gate  * allocation.
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate typedef struct agp_pmem_handle {
707c478bd9Sstevel@tonic-gate 	devmap_pmem_cookie_t pmem_cookie;
717c478bd9Sstevel@tonic-gate } agp_pmem_handle_t;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * This struct is used for DDI-compliant memory allocations.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate typedef struct agp_kmem_handle {
777c478bd9Sstevel@tonic-gate 	ddi_dma_handle_t	kmem_handle;
787c478bd9Sstevel@tonic-gate 	ddi_dma_cookie_t	kmem_dcookie;
797c478bd9Sstevel@tonic-gate 	uint32_t		kmem_cookies_num;
807c478bd9Sstevel@tonic-gate 	caddr_t			kmem_kvaddr;
817c478bd9Sstevel@tonic-gate 	size_t			kmem_reallen;
827c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	kmem_acchdl;
837c478bd9Sstevel@tonic-gate } agp_kmem_handle_t;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate typedef struct keytable_ent {
867c478bd9Sstevel@tonic-gate 	int		kte_type; 	/* agp memory type */
877c478bd9Sstevel@tonic-gate 	int		kte_key;	/* memory key */
887c478bd9Sstevel@tonic-gate 	uint32_t	kte_pgoff;	/* aperture offset bound in pages */
897c478bd9Sstevel@tonic-gate 	pgcnt_t		kte_pages;	/* user-requested size in pages */
907c478bd9Sstevel@tonic-gate 	int		kte_bound;	/* bound to gart table */
917c478bd9Sstevel@tonic-gate 	void		*kte_memhdl;	/* agp_kmem or agp_pmem handle */
927c478bd9Sstevel@tonic-gate 	pfn_t		*kte_pfnarray;	/* page frame numbers allocated */
93b5d3ab78Shh224818 	int	kte_refcnt;	/* reference count */
947c478bd9Sstevel@tonic-gate } keytable_ent_t;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate typedef struct key_list {
977c478bd9Sstevel@tonic-gate 	int	key_idx;
987c478bd9Sstevel@tonic-gate 	struct	key_list *next;
997c478bd9Sstevel@tonic-gate } key_list_t;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * for kstat
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate typedef struct agp_kern_info {
1057c478bd9Sstevel@tonic-gate 	uint32_t	agpki_mdevid;
1067c478bd9Sstevel@tonic-gate 	agp_version_t	agpki_mver;
1077c478bd9Sstevel@tonic-gate 	uint32_t	agpki_mstatus;
1087c478bd9Sstevel@tonic-gate 	size_t		agpki_presize;	/* valid only for IGD, in KB */
1097c478bd9Sstevel@tonic-gate 	uint32_t	agpki_tdevid;
1107c478bd9Sstevel@tonic-gate 	agp_version_t	agpki_tver;
1117c478bd9Sstevel@tonic-gate 	uint32_t	agpki_tstatus;
1127c478bd9Sstevel@tonic-gate 	uint64_t	agpki_aperbase;
1137c478bd9Sstevel@tonic-gate 	uint32_t	agpki_apersize;	/* in MB */
1147c478bd9Sstevel@tonic-gate } agp_kern_info_t;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate #ifdef	_MULTI_DATAMODEL
1177c478bd9Sstevel@tonic-gate typedef struct _agp_info32 {
1187c478bd9Sstevel@tonic-gate 	agp_version_t	agpi32_version;
1197c478bd9Sstevel@tonic-gate 	uint32_t	agpi32_devid; /* device VID + DID */
1207c478bd9Sstevel@tonic-gate 	uint32_t	agpi32_mode; /* mode of bridge */
1217c478bd9Sstevel@tonic-gate 	uint32_t	agpi32_aperbase; /* base of aperture */
1227c478bd9Sstevel@tonic-gate 	uint32_t	agpi32_apersize; /* in MB */
1237c478bd9Sstevel@tonic-gate 	uint32_t	agpi32_pgtotal;	/* max number of pages */
1247c478bd9Sstevel@tonic-gate 	uint32_t	agpi32_pgsystem; /* same as pg_total */
1257c478bd9Sstevel@tonic-gate 	uint32_t	agpi32_pgused; /* pages consumed */
1267c478bd9Sstevel@tonic-gate } agp_info32_t;
1277c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */
1287c478bd9Sstevel@tonic-gate 
129*0035d21cSmiao chen - Sun Microsystems - Beijing China struct list_head {
130*0035d21cSmiao chen - Sun Microsystems - Beijing China 	struct list_head *next, *prev;
131*0035d21cSmiao chen - Sun Microsystems - Beijing China 	struct igd_gtt_seg  *gttseg;
132*0035d21cSmiao chen - Sun Microsystems - Beijing China };
133*0035d21cSmiao chen - Sun Microsystems - Beijing China 
134*0035d21cSmiao chen - Sun Microsystems - Beijing China 
1357c478bd9Sstevel@tonic-gate typedef struct	agpgart_softstate {
1367c478bd9Sstevel@tonic-gate 	dev_info_t	*asoft_dip;
1377c478bd9Sstevel@tonic-gate 	kmutex_t	asoft_instmutex;
1387c478bd9Sstevel@tonic-gate 	agp_kern_info_t	asoft_info;
1397c478bd9Sstevel@tonic-gate 	int		asoft_opened;	/* 0 not opened, non-0 opened */
1407c478bd9Sstevel@tonic-gate 	int		asoft_acquired;	/* 0 released, 1 acquired */
1417c478bd9Sstevel@tonic-gate 	int		asoft_agpen;	/* 0 disbaled, 1 enabled */
1427c478bd9Sstevel@tonic-gate 	pid_t		asoft_curpid;	/* the process accquiring gart */
1437c478bd9Sstevel@tonic-gate 	uint32_t	asoft_mode;	/* agp mode be set */
1447c478bd9Sstevel@tonic-gate 	uint32_t	asoft_pgtotal;	/* total available pages */
1457c478bd9Sstevel@tonic-gate 	uint32_t	asoft_pgused;	/* pages already used */
1467c478bd9Sstevel@tonic-gate 	/* resource handles */
1477c478bd9Sstevel@tonic-gate 	ldi_ident_t	asoft_li;	/* for ldi ops */
1487c478bd9Sstevel@tonic-gate 	keytable_ent_t	*asoft_table;	/* key table for all allocated table */
1497c478bd9Sstevel@tonic-gate 	ddi_dma_handle_t	gart_dma_handle; 	/* for GATT table */
1507c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	gart_dma_acc_handle;	/* for GATT table */
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	/* gart table info */
1537c478bd9Sstevel@tonic-gate 	uint64_t	gart_pbase; /* gart table physical address */
1547c478bd9Sstevel@tonic-gate 	caddr_t		gart_vbase; /* kernel-vir addr for GATT table */
1557c478bd9Sstevel@tonic-gate 	size_t		gart_size;  /* the size of aperture in megabytes */
1567c478bd9Sstevel@tonic-gate 	/* all registered agp device in here */
1577c478bd9Sstevel@tonic-gate 	agp_registered_dev_t	asoft_devreg;
1587c478bd9Sstevel@tonic-gate 	kstat_t			*asoft_ksp;
159*0035d21cSmiao chen - Sun Microsystems - Beijing China 	struct		list_head	mapped_list;
1607c478bd9Sstevel@tonic-gate } agpgart_softstate_t;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate typedef struct agpgart_ctx {
1637c478bd9Sstevel@tonic-gate 	offset_t	actx_off;
1647c478bd9Sstevel@tonic-gate 	agpgart_softstate_t *actx_sc;
1657c478bd9Sstevel@tonic-gate } agpgart_ctx_t;
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate #define	KMEMP(p)		((agp_kmem_handle_t *)p)
1687c478bd9Sstevel@tonic-gate #define	PMEMP(p)		((agp_pmem_handle_t *)p)
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate int agp_init_kstats(agpgart_softstate_t *);
1717c478bd9Sstevel@tonic-gate void agp_fini_kstats(agpgart_softstate_t *);
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate #endif
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate #endif /* _SYS_AGPGART_IMPL_H */
180