xref: /illumos-gate/usr/src/uts/common/sys/gfx_private.h (revision 2a6e99a0f1f7d22c0396e8b2ce9b9babbd1056cf)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * This file defines interfaces consumed by the AGP kernel modules,
28  * and indirectly by the DRM system.  Please consider everything in
29  * this file to be a "contract private interface", and keep in sync
30  * with the consumers in the "DRM" gate.
31  */
32 
33 #ifndef	_GFX_PRIVATE_H
34 #define	_GFX_PRIVATE_H
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /* Memory cache attributes */
41 #define	GFXP_MEMORY_CACHED		0
42 #define	GFXP_MEMORY_UNCACHED		1
43 #define	GFXP_MEMORY_WRITECOMBINED	2
44 
45 typedef uint64_t gfx_maddr_t;
46 
47 extern int gfxp_ddi_segmap_setup(dev_t dev, off_t offset, struct as *as,
48 	caddr_t *addrp, off_t len, uint_t prot, uint_t maxprot, uint_t flags,
49 	cred_t *cred, ddi_device_acc_attr_t *accattrp, uint_t rnumber);
50 
51 extern ddi_umem_cookie_t gfxp_umem_cookie_init(caddr_t kva, size_t size);
52 extern void gfxp_umem_cookie_destroy(ddi_umem_cookie_t cookie);
53 extern int gfxp_devmap_umem_setup(devmap_cookie_t dhc, dev_info_t *dip,
54 	struct devmap_callback_ctl *callbackops, ddi_umem_cookie_t cookie,
55 	offset_t off, size_t len, uint_t maxprot, uint_t flags,
56 	ddi_device_acc_attr_t *accattrp);
57 extern void gfxp_map_devmem(devmap_cookie_t dhc, gfx_maddr_t maddr,
58 	size_t length, ddi_device_acc_attr_t *attrp);
59 
60 
61 typedef char *gfxp_acc_handle_t;
62 extern gfxp_acc_handle_t gfxp_pci_init_handle(uint8_t bus, uint8_t slot,
63 	uint8_t function, uint16_t *vendor, uint16_t *device);
64 extern uint8_t gfxp_pci_read_byte(gfxp_acc_handle_t handle, uint16_t offset);
65 extern uint16_t gfxp_pci_read_word(gfxp_acc_handle_t handle, uint16_t offset);
66 extern uint32_t gfxp_pci_read_dword(gfxp_acc_handle_t handle, uint16_t offset);
67 extern void gfxp_pci_write_byte(gfxp_acc_handle_t handle, uint16_t offset,
68 	uint8_t value);
69 extern void gfxp_pci_write_word(gfxp_acc_handle_t handle, uint16_t offset,
70 	uint16_t value);
71 extern void gfxp_pci_write_dword(gfxp_acc_handle_t handle, uint16_t offset,
72 	uint32_t value);
73 extern int gfxp_pci_device_present(uint16_t vendor, uint16_t device);
74 
75 typedef char *gfxp_kva_t;
76 extern gfxp_kva_t gfxp_map_kernel_space(uint64_t start, size_t size,
77 	uint32_t mode);
78 extern void gfxp_unmap_kernel_space(gfxp_kva_t address, size_t size);
79 extern int gfxp_va2pa(struct as *as, caddr_t addr, uint64_t *pa);
80 extern void gfxp_fix_mem_cache_attrs(caddr_t kva_start, size_t length,
81 	int cache_attr);
82 extern gfx_maddr_t gfxp_convert_addr(paddr_t paddr);
83 
84 typedef char *gfxp_vgatext_softc_ptr_t;
85 
86 extern gfxp_vgatext_softc_ptr_t gfxp_vgatext_softc_alloc(void);
87 extern void gfxp_vgatext_softc_free(gfxp_vgatext_softc_ptr_t ptr);
88 extern int gfxp_vgatext_attach(dev_info_t *devi, ddi_attach_cmd_t cmd,
89 	gfxp_vgatext_softc_ptr_t ptr);
90 extern int gfxp_vgatext_detach(dev_info_t *devi, ddi_detach_cmd_t cmd,
91 	gfxp_vgatext_softc_ptr_t ptr);
92 extern int gfxp_vgatext_open(dev_t *devp, int flag, int otyp, cred_t *cred,
93 	gfxp_vgatext_softc_ptr_t ptr);
94 extern int gfxp_vgatext_close(dev_t devp, int flag, int otyp, cred_t *cred,
95 	gfxp_vgatext_softc_ptr_t ptr);
96 extern int gfxp_vgatext_ioctl(dev_t dev, int cmd, intptr_t data, int mode,
97 	cred_t *cred, int *rval, gfxp_vgatext_softc_ptr_t ptr);
98 
99 extern int gfxp_mlock_user_memory(caddr_t address, size_t length);
100 extern int gfxp_munlock_user_memory(caddr_t address, size_t length);
101 extern int gfxp_vgatext_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off,
102 	size_t len, size_t *maplen, uint_t model, void *ptr);
103 
104 
105 /*
106  * Updated "glue" for newer libdrm code.
107  * See: kernel/drm/src/drm_fb_helper.c
108  */
109 
110 /* Same as: gfxp_vgatext_softc_ptr_t; */
111 typedef char *gfxp_fb_softc_ptr_t;
112 
113 /*
114  * Used by drm_register_fbops().
115  * Note: only setmode is supplied.
116  */
117 struct gfxp_blt_ops {
118 	int (*blt)(void *);
119 	int (*copy) (void *);
120 	int (*clear) (void *);
121 	int (*setmode) (int);
122 };
123 
124 extern void gfxp_bm_register_fbops(gfxp_fb_softc_ptr_t,
125     struct gfxp_blt_ops *);
126 
127 /* See: kernel/drm/src/drm_fb_helper.c */
128 
129 struct gfxp_bm_fb_info {
130 	uint16_t xres;
131 	uint16_t yres;
132 	uint8_t bpp;
133 	uint8_t depth;
134 };
135 
136 void gfxp_bm_getfb_info(gfxp_fb_softc_ptr_t, struct gfxp_bm_fb_info *);
137 
138 /* See: kernel/drm/src/drm_bufs.c etc */
139 
140 caddr_t	gfxp_alloc_kernel_space(size_t size);	/* vmem_alloc heap_arena */
141 void	gfxp_free_kernel_space(caddr_t address, size_t size);
142 
143 void	gfxp_load_kernel_space(uint64_t start, size_t size,
144 				uint32_t mode, caddr_t cvaddr);
145 void	gfxp_unload_kernel_space(caddr_t address, size_t size);
146 
147 /*
148  * Note that "mempool" is optional and normally disabled in drm_gem.c
149  * (see HAS_MEM_POOL).  Let's just stub these out so we can reduce
150  * changes from the upstream in the DRM driver code.
151  */
152 struct gfxp_pmem_cookie {
153 	ulong_t a, b, c;
154 };
155 void	gfxp_mempool_init(void);
156 void	gfxp_mempool_destroy(void);
157 int gfxp_alloc_from_mempool(struct gfxp_pmem_cookie *, caddr_t *,
158 			    pfn_t *, pgcnt_t, int);
159 void gfxp_free_mempool(struct gfxp_pmem_cookie *, caddr_t, size_t);
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 #endif /* _GFX_PRIVATE_H */
166