4309b6e2f71d0fd7a454e9186440faaf783ce4c4
[dragonfly.git] / sys / dev / drm / include / drm / intel-gtt.h
1 /*-
2  * Copyright (c) 2011 The FreeBSD Foundation
3  * All rights reserved.
4  *
5  * This software was developed by Konstantin Belousov under sponsorship from
6  * the FreeBSD Foundation.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #ifndef AGP_AGP_I810_H
31 #define AGP_AGP_I810_H
32
33 #include <sys/param.h>
34 #include <sys/sglist.h>
35
36 #include <vm/vm.h>
37 #include <vm/vm_page.h>
38
39 #include <linux/types.h>
40
41 /* Special gtt memory types */
42 #define AGP_DCACHE_MEMORY       1
43 #define AGP_PHYS_MEMORY         2
44
45 /* New caching attributes for gen6/sandybridge */
46 #define AGP_USER_CACHED_MEMORY_LLC_MLC (AGP_USER_TYPES + 2)
47 #define AGP_USER_UNCACHED_MEMORY (AGP_USER_TYPES + 4)
48
49 /* flag for GFDT type */
50 #define AGP_USER_CACHED_MEMORY_GFDT (1 << 3)
51
52 struct intel_gtt {
53         /* Size of memory reserved for graphics by the BIOS */
54         u_int stolen_size;
55         /* Total number of gtt entries. */
56         u_int gtt_total_entries;
57         /* Part of the gtt that is mappable by the cpu, for those chips where
58          * this is not the full gtt. */
59         u_int gtt_mappable_entries;
60         /* Whether we idle the gpu before mapping/unmapping */
61         unsigned int do_idle_maps : 1;
62         /* Share the scratch page dma with ppgtts. */
63         vm_paddr_t scratch_page_dma;
64         struct vm_page *scratch_page;
65         /* for ppgtt PDE access */
66         uint32_t *gtt;
67         /* needed for ioremap in drm/i915 */
68         bus_addr_t gma_bus_addr;
69 };
70
71 struct intel_gtt agp_intel_gtt_get(device_t dev);
72 int agp_intel_gtt_chipset_flush(device_t dev);
73 void agp_intel_gtt_unmap_memory(device_t dev, struct sglist *sg_list);
74 void agp_intel_gtt_clear_range(device_t dev, u_int first_entry,
75     u_int num_entries);
76 int agp_intel_gtt_map_memory(device_t dev, vm_page_t *pages, u_int num_entries,
77     struct sglist **sg_list);
78 void agp_intel_gtt_insert_sg_entries(device_t dev, struct sglist *sg_list,
79     u_int pg_start, u_int flags);
80 void agp_intel_gtt_insert_pages(device_t dev, u_int first_entry,
81     u_int num_entries, vm_page_t *pages, u_int flags);
82
83 void intel_gtt_get(size_t *gtt_total, size_t *stolen_size,
84                    phys_addr_t *mappable_base, unsigned long *mappable_end);
85
86 int intel_gtt_chipset_flush(void);
87 void intel_gtt_unmap_memory(struct sglist *sg_list);
88 void intel_gtt_clear_range(u_int first_entry, u_int num_entries);
89 int intel_gtt_map_memory(vm_page_t *pages, u_int num_entries,
90     struct sglist **sg_list);
91 void intel_gtt_insert_sg_entries(struct sglist *sg_list, u_int pg_start,
92     u_int flags);
93 void intel_gtt_insert_pages(u_int first_entry, u_int num_entries,
94     vm_page_t *pages, u_int flags);
95 void intel_gtt_sync_pte(u_int entry);
96 void intel_gtt_write(u_int entry, uint32_t val);
97
98 #endif