xref: /illumos-gate/usr/src/uts/common/sys/gfx_private.h (revision 78801af7286cd73dbc996d470f789e75993cf15d)
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 
41 /*
42  * Updated "glue" for newer libdrm code.
43  * See: kernel/drm/src/drm_fb_helper.c
44  */
45 
46 typedef char *gfxp_fb_softc_ptr_t;
47 
48 /* Memory cache attributes */
49 #define	GFXP_MEMORY_CACHED		0
50 #define	GFXP_MEMORY_UNCACHED		1
51 #define	GFXP_MEMORY_WRITECOMBINED	2
52 
53 enum gfxp_type {
54 	GFXP_BITMAP,
55 	GFXP_VGATEXT
56 };
57 
58 typedef uint64_t gfx_maddr_t;
59 typedef char *gfxp_acc_handle_t;
60 
61 extern int gfxp_ddi_segmap_setup(dev_t dev, off_t offset, struct as *as,
62 	caddr_t *addrp, off_t len, uint_t prot, uint_t maxprot, uint_t flags,
63 	cred_t *cred, ddi_device_acc_attr_t *accattrp, uint_t rnumber);
64 
65 extern ddi_umem_cookie_t gfxp_umem_cookie_init(caddr_t kva, size_t size);
66 extern void gfxp_umem_cookie_destroy(ddi_umem_cookie_t cookie);
67 extern int gfxp_devmap_umem_setup(devmap_cookie_t dhc, dev_info_t *dip,
68 	struct devmap_callback_ctl *callbackops, ddi_umem_cookie_t cookie,
69 	offset_t off, size_t len, uint_t maxprot, uint_t flags,
70 	ddi_device_acc_attr_t *accattrp);
71 extern void gfxp_map_devmem(devmap_cookie_t dhc, gfx_maddr_t maddr,
72 	size_t length, ddi_device_acc_attr_t *attrp);
73 
74 extern gfxp_acc_handle_t gfxp_pci_init_handle(uint8_t bus, uint8_t slot,
75 	uint8_t function, uint16_t *vendor, uint16_t *device);
76 extern uint8_t gfxp_pci_read_byte(gfxp_acc_handle_t handle, uint16_t offset);
77 extern uint16_t gfxp_pci_read_word(gfxp_acc_handle_t handle, uint16_t offset);
78 extern uint32_t gfxp_pci_read_dword(gfxp_acc_handle_t handle, uint16_t offset);
79 extern void gfxp_pci_write_byte(gfxp_acc_handle_t handle, uint16_t offset,
80 	uint8_t value);
81 extern void gfxp_pci_write_word(gfxp_acc_handle_t handle, uint16_t offset,
82 	uint16_t value);
83 extern void gfxp_pci_write_dword(gfxp_acc_handle_t handle, uint16_t offset,
84 	uint32_t value);
85 extern int gfxp_pci_device_present(uint16_t vendor, uint16_t device);
86 
87 typedef char *gfxp_kva_t;
88 extern gfxp_kva_t gfxp_map_kernel_space(uint64_t start, size_t size,
89 	uint32_t mode);
90 extern void gfxp_unmap_kernel_space(gfxp_kva_t address, size_t size);
91 extern int gfxp_va2pa(struct as *as, caddr_t addr, uint64_t *pa);
92 extern void gfxp_fix_mem_cache_attrs(caddr_t kva_start, size_t length,
93 	int cache_attr);
94 extern gfx_maddr_t gfxp_convert_addr(paddr_t paddr);
95 
96 extern gfxp_fb_softc_ptr_t gfxp_fb_softc_alloc(void);
97 extern void gfxp_fb_softc_free(gfxp_fb_softc_ptr_t ptr);
98 extern int gfxp_fb_attach(dev_info_t *devi, ddi_attach_cmd_t cmd,
99 	gfxp_fb_softc_ptr_t ptr);
100 extern int gfxp_fb_detach(dev_info_t *devi, ddi_detach_cmd_t cmd,
101 	gfxp_fb_softc_ptr_t ptr);
102 extern int gfxp_fb_open(dev_t *devp, int flag, int otyp, cred_t *cred,
103 	gfxp_fb_softc_ptr_t ptr);
104 extern int gfxp_fb_close(dev_t devp, int flag, int otyp, cred_t *cred,
105 	gfxp_fb_softc_ptr_t ptr);
106 extern int gfxp_fb_ioctl(dev_t dev, int cmd, intptr_t data, int mode,
107 	cred_t *cred, int *rval, gfxp_fb_softc_ptr_t ptr);
108 
109 extern int gfxp_mlock_user_memory(caddr_t address, size_t length);
110 extern int gfxp_munlock_user_memory(caddr_t address, size_t length);
111 extern int gfxp_fb_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off,
112 	size_t len, size_t *maplen, uint_t model, void *ptr);
113 
114 /*
115  * Used by drm_register_fbops().
116  * Note: only setmode is supplied.
117  */
118 struct gfxp_blt_ops {
119 	int (*blt)(void *);
120 	int (*copy) (void *);
121 	int (*clear) (void *);
122 	int (*setmode) (int);
123 };
124 
125 extern void gfxp_bm_register_fbops(gfxp_fb_softc_ptr_t,
126     struct gfxp_blt_ops *);
127 
128 /* See: kernel/drm/src/drm_fb_helper.c */
129 
130 struct gfxp_bm_fb_info {
131 	uint16_t xres;
132 	uint16_t yres;
133 	uint8_t bpp;
134 	uint8_t depth;
135 };
136 
137 void gfxp_bm_getfb_info(gfxp_fb_softc_ptr_t, struct gfxp_bm_fb_info *);
138 
139 /* See: kernel/drm/src/drm_bufs.c etc */
140 
141 caddr_t	gfxp_alloc_kernel_space(size_t size);	/* vmem_alloc heap_arena */
142 void	gfxp_free_kernel_space(caddr_t address, size_t size);
143 
144 void	gfxp_load_kernel_space(uint64_t start, size_t size,
145 				uint32_t mode, caddr_t cvaddr);
146 void	gfxp_unload_kernel_space(caddr_t address, size_t size);
147 
148 /*
149  * Note that "mempool" is optional and normally disabled in drm_gem.c
150  * (see HAS_MEM_POOL).  Let's just stub these out so we can reduce
151  * changes from the upstream in the DRM driver code.
152  */
153 struct gfxp_pmem_cookie {
154 	ulong_t a, b, c;
155 };
156 void	gfxp_mempool_init(void);
157 void	gfxp_mempool_destroy(void);
158 int gfxp_alloc_from_mempool(struct gfxp_pmem_cookie *, caddr_t *,
159 			    pfn_t *, pgcnt_t, int);
160 void gfxp_free_mempool(struct gfxp_pmem_cookie *, caddr_t, size_t);
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif /* _GFX_PRIVATE_H */
167