Eric Anholt | fbbf124 | 2009-03-27 12:25:09 -0700 | [diff] [blame] | 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 | |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 28 | #include <stdint.h> |
Eric Anholt | fbbf124 | 2009-03-27 12:25:09 -0700 | [diff] [blame] | 29 | #include <sys/types.h> |
| 30 | #include <pciaccess.h> |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 31 | |
Eric Anholt | fbbf124 | 2009-03-27 12:25:09 -0700 | [diff] [blame] | 32 | #include "intel_chipset.h" |
Eric Anholt | ce4782d | 2009-03-27 16:11:50 -0700 | [diff] [blame] | 33 | #include "intel_reg.h" |
Eric Anholt | fbbf124 | 2009-03-27 12:25:09 -0700 | [diff] [blame] | 34 | |
Eric Anholt | 40bff50 | 2009-10-06 17:25:10 -0700 | [diff] [blame] | 35 | #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) |
| 36 | |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 37 | extern void *mmio; |
| 38 | void intel_get_mmio(struct pci_device *pci_dev); |
| 39 | |
Ben Widawsky | cac8f8b | 2011-07-28 13:40:19 -0700 | [diff] [blame] | 40 | /* New style register access API */ |
Ben Widawsky | abd7038 | 2011-07-28 13:42:45 -0700 | [diff] [blame^] | 41 | int intel_register_access_init(struct pci_device *pci_dev, int safe); |
Ben Widawsky | cac8f8b | 2011-07-28 13:40:19 -0700 | [diff] [blame] | 42 | void intel_register_access_fini(void); |
| 43 | uint32_t intel_register_read(uint32_t reg); |
| 44 | void intel_register_write(uint32_t reg, uint32_t val); |
| 45 | |
Ben Widawsky | abd7038 | 2011-07-28 13:42:45 -0700 | [diff] [blame^] | 46 | #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 | |
| 52 | struct intel_register_range { |
| 53 | uint32_t base; |
| 54 | uint32_t size; |
| 55 | uint32_t flags; |
| 56 | }; |
| 57 | |
| 58 | struct intel_register_map { |
| 59 | struct intel_register_range *map; |
| 60 | uint32_t top; |
| 61 | uint32_t alignment_mask; |
| 62 | }; |
| 63 | struct intel_register_map intel_get_register_map(uint32_t devid); |
| 64 | struct intel_register_range *intel_get_register_range(struct intel_register_map map, uint32_t offset, int mode); |
| 65 | |
| 66 | |
Eric Anholt | fbbf124 | 2009-03-27 12:25:09 -0700 | [diff] [blame] | 67 | static inline uint32_t |
| 68 | INREG(uint32_t reg) |
| 69 | { |
| 70 | return *(volatile uint32_t *)((volatile char *)mmio + reg); |
| 71 | } |
| 72 | |
Wu Fengguang | 9e9c9f2 | 2009-11-06 11:06:22 +0800 | [diff] [blame] | 73 | static inline void |
| 74 | OUTREG(uint32_t reg, uint32_t val) |
| 75 | { |
| 76 | *(volatile uint32_t *)((volatile char *)mmio + reg) = val; |
| 77 | } |
| 78 | |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 79 | struct pci_device *intel_get_pci_device(void); |
| 80 | |
| 81 | uint32_t intel_get_drm_devid(int fd); |
| 82 | |
Adam Jackson | cd64e19 | 2010-03-31 17:25:23 -0400 | [diff] [blame] | 83 | void intel_map_file(char *); |
Zhenyu Wang | 2b40fc8 | 2010-04-15 22:57:02 +0800 | [diff] [blame] | 84 | |
| 85 | enum pch_type { |
| 86 | PCH_IBX, |
| 87 | PCH_CPT, |
| 88 | }; |
| 89 | |
| 90 | extern enum pch_type pch; |
| 91 | void intel_check_pch(void); |
| 92 | |
| 93 | #define HAS_CPT (pch == PCH_CPT) |