1 /*
2  * Copyright © 2015 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 FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #ifndef __INTEL_REG_SPEC_H__
25 #define __INTEL_REG_SPEC_H__
26 
27 enum port_addr {
28 	PORT_NONE = 0,
29 	PORT_MMIO = -1,
30 	PORT_PORTIO_VGA = -2,	/* see vga reg read/write */
31 	PORT_MMIO_VGA = -3,	/* see vga reg read/write */
32 
33 	/* vlv */
34 	PORT_BUNIT = 0x03,
35 	PORT_PUNIT = 0x04,
36 	PORT_NC = 0x11,
37 	PORT_DPIO = 0x12,
38 	PORT_GPIO_NC = 0x13,
39 	PORT_CCK = 0x14,
40 	PORT_CCU = 0xa9,
41 	PORT_DPIO2 = 0x1a,
42 	PORT_FLISDSI = 0x1b,
43 
44 	/* threshold for interpreting port as mmio offset */
45 	PORT_MAX = 0xff,
46 };
47 
48 struct port_desc {
49 	enum port_addr port;
50 	const char *name;
51 	uint32_t stride;
52 };
53 
54 struct reg {
55 	struct port_desc port_desc;
56 	char *engine;
57 	uint32_t mmio_offset;
58 	uint32_t addr;
59 	char *name;
60 };
61 
62 #ifndef ARRAY_SIZE
63 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
64 #endif
65 
recalloc(void * ptr,size_t nmemb,size_t size)66 static inline void *recalloc(void *ptr, size_t nmemb, size_t size)
67 {
68 	return realloc(ptr, nmemb * size);
69 }
70 
71 int parse_port_desc(struct reg *reg, const char *s);
72 ssize_t intel_reg_spec_builtin(struct reg **regs, uint32_t devid);
73 ssize_t intel_reg_spec_file(struct reg **regs, const char *filename);
74 void intel_reg_spec_free(struct reg *regs, size_t n);
75 int intel_reg_spec_decode(char *buf, size_t bufsize, const struct reg *reg,
76 			  uint32_t val, uint32_t devid);
77 void intel_reg_spec_print_ports(void);
78 
79 #endif /* __INTEL_REG_SPEC_H__ */
80