blob: a145fb9bff64d4db9bd7b5385ad72589b7ec71f8 [file] [log] [blame]
Eric Anholtfbbf1242009-03-27 12:25:09 -07001/*
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
Chris Wilson95374222010-04-08 11:56:57 +010028#include <stdint.h>
Eric Anholtfbbf1242009-03-27 12:25:09 -070029#include <sys/types.h>
30#include <pciaccess.h>
Chris Wilson95374222010-04-08 11:56:57 +010031
Eric Anholtfbbf1242009-03-27 12:25:09 -070032#include "intel_chipset.h"
Eric Anholtce4782d2009-03-27 16:11:50 -070033#include "intel_reg.h"
Eric Anholtfbbf1242009-03-27 12:25:09 -070034
Eric Anholt40bff502009-10-06 17:25:10 -070035#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
36
Chris Wilson95374222010-04-08 11:56:57 +010037extern void *mmio;
38void intel_get_mmio(struct pci_device *pci_dev);
39
Ben Widawskycac8f8b2011-07-28 13:40:19 -070040/* New style register access API */
Ben Widawskyabd70382011-07-28 13:42:45 -070041int intel_register_access_init(struct pci_device *pci_dev, int safe);
Ben Widawskycac8f8b2011-07-28 13:40:19 -070042void intel_register_access_fini(void);
43uint32_t intel_register_read(uint32_t reg);
44void intel_register_write(uint32_t reg, uint32_t val);
45
Ben Widawskyabd70382011-07-28 13:42:45 -070046#define INTEL_RANGE_RSVD (0<<0) /* Shouldn't be read or written */
47#define INTEL_RANGE_READ (1<<0)
48#define INTEL_RANGE_WRITE (1<<1)
49#define INTEL_RANGE_RW (INTEL_RANGE_READ | INTEL_RANGE_WRITE)
50#define INTEL_RANGE_END (1<<31)
51
52struct intel_register_range {
53 uint32_t base;
54 uint32_t size;
55 uint32_t flags;
56};
57
58struct intel_register_map {
59 struct intel_register_range *map;
60 uint32_t top;
61 uint32_t alignment_mask;
62};
63struct intel_register_map intel_get_register_map(uint32_t devid);
64struct intel_register_range *intel_get_register_range(struct intel_register_map map, uint32_t offset, int mode);
65
66
Eric Anholtfbbf1242009-03-27 12:25:09 -070067static inline uint32_t
68INREG(uint32_t reg)
69{
70 return *(volatile uint32_t *)((volatile char *)mmio + reg);
71}
72
Wu Fengguang9e9c9f22009-11-06 11:06:22 +080073static inline void
74OUTREG(uint32_t reg, uint32_t val)
75{
76 *(volatile uint32_t *)((volatile char *)mmio + reg) = val;
77}
78
Chris Wilson95374222010-04-08 11:56:57 +010079struct pci_device *intel_get_pci_device(void);
80
81uint32_t intel_get_drm_devid(int fd);
82
Adam Jacksoncd64e192010-03-31 17:25:23 -040083void intel_map_file(char *);
Zhenyu Wang2b40fc82010-04-15 22:57:02 +080084
85enum pch_type {
86 PCH_IBX,
87 PCH_CPT,
88};
89
90extern enum pch_type pch;
91void intel_check_pch(void);
92
93#define HAS_CPT (pch == PCH_CPT)