1 /*
2 * Copyright © 2009 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28 #ifndef INTEL_GPU_TOOLS_H
29 #define INTEL_GPU_TOOLS_H
30
31 #include <stdint.h>
32 #include <sys/types.h>
33 #include <pciaccess.h>
34
35 #include "intel_chipset.h"
36 #include "intel_reg.h"
37
38 #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
39
40 extern void *mmio;
41 void intel_get_mmio(struct pci_device *pci_dev);
42
43 /* New style register access API */
44 int intel_register_access_init(struct pci_device *pci_dev, int safe);
45 void intel_register_access_fini(void);
46 uint32_t intel_register_read(uint32_t reg);
47 void intel_register_write(uint32_t reg, uint32_t val);
48 int intel_register_access_needs_fakewake(void);
49
50 /* Following functions are relevant only for SoCs like Valleyview */
51 uint32_t intel_dpio_reg_read(uint32_t reg);
52 void intel_dpio_reg_write(uint32_t reg, uint32_t val);
53
54 int intel_punit_read(uint8_t addr, uint32_t *val);
55 int intel_punit_write(uint8_t addr, uint32_t val);
56 int intel_nc_read(uint8_t addr, uint32_t *val);
57 int intel_nc_write(uint8_t addr, uint32_t val);
58
59 #define INTEL_RANGE_RSVD (0<<0) /* Shouldn't be read or written */
60 #define INTEL_RANGE_READ (1<<0)
61 #define INTEL_RANGE_WRITE (1<<1)
62 #define INTEL_RANGE_RW (INTEL_RANGE_READ | INTEL_RANGE_WRITE)
63 #define INTEL_RANGE_END (1<<31)
64
65 struct intel_register_range {
66 uint32_t base;
67 uint32_t size;
68 uint32_t flags;
69 };
70
71 struct intel_register_map {
72 struct intel_register_range *map;
73 uint32_t top;
74 uint32_t alignment_mask;
75 };
76 struct intel_register_map intel_get_register_map(uint32_t devid);
77 struct intel_register_range *intel_get_register_range(struct intel_register_map map, uint32_t offset, int mode);
78
79
80 static inline uint32_t
INREG(uint32_t reg)81 INREG(uint32_t reg)
82 {
83 return *(volatile uint32_t *)((volatile char *)mmio + reg);
84 }
85
86 static inline void
OUTREG(uint32_t reg,uint32_t val)87 OUTREG(uint32_t reg, uint32_t val)
88 {
89 *(volatile uint32_t *)((volatile char *)mmio + reg) = val;
90 }
91
92 struct pci_device *intel_get_pci_device(void);
93
94 uint32_t intel_get_drm_devid(int fd);
95 int intel_gen(uint32_t devid);
96 uint64_t intel_get_total_ram_mb(void);
97 uint64_t intel_get_total_swap_mb(void);
98
99 void intel_map_file(char *);
100
101 enum pch_type {
102 PCH_NONE,
103 PCH_IBX,
104 PCH_CPT,
105 PCH_LPT,
106 PCH_SPT,
107 PCH_KBP,
108 };
109
110 extern enum pch_type pch;
111 void intel_check_pch(void);
112
113 #define HAS_IBX (pch == PCH_IBX)
114 #define HAS_CPT (pch == PCH_CPT)
115 #define HAS_LPT (pch == PCH_LPT)
116
117 #endif /* INTEL_GPU_TOOLS_H */
118