1/* SPDX-License-Identifier: MIT */ 2/* 3 * Copyright �� 2021-2023 Intel Corporation 4 */ 5 6#ifndef _XE_MMIO_H_ 7#define _XE_MMIO_H_ 8 9#include <linux/delay.h> 10#include <linux/io-64-nonatomic-lo-hi.h> 11 12#include "regs/xe_reg_defs.h" 13#include "xe_device_types.h" 14#include "xe_gt_printk.h" 15#include "xe_gt_types.h" 16 17struct drm_device; 18struct drm_file; 19struct xe_device; 20 21#define LMEM_BAR 2 22 23int xe_mmio_init(struct xe_device *xe); 24int xe_mmio_root_tile_init(struct xe_device *xe); 25void xe_mmio_probe_tiles(struct xe_device *xe); 26 27static inline u8 xe_mmio_read8(struct xe_gt *gt, struct xe_reg reg) 28{ 29 struct xe_tile *tile = gt_to_tile(gt); 30 31 if (reg.addr < gt->mmio.adj_limit) 32 reg.addr += gt->mmio.adj_offset; 33 34 return readb((reg.ext ? tile->mmio_ext.regs : tile->mmio.regs) + reg.addr); 35} 36 37static inline u16 xe_mmio_read16(struct xe_gt *gt, struct xe_reg reg) 38{ 39 struct xe_tile *tile = gt_to_tile(gt); 40 41 if (reg.addr < gt->mmio.adj_limit) 42 reg.addr += gt->mmio.adj_offset; 43 44 return readw((reg.ext ? tile->mmio_ext.regs : tile->mmio.regs) + reg.addr); 45} 46 47static inline void xe_mmio_write32(struct xe_gt *gt, 48 struct xe_reg reg, u32 val) 49{ 50 struct xe_tile *tile = gt_to_tile(gt); 51 52 if (reg.addr < gt->mmio.adj_limit) 53 reg.addr += gt->mmio.adj_offset; 54 55 writel(val, (reg.ext ? tile->mmio_ext.regs : tile->mmio.regs) + reg.addr); 56} 57 58static inline u32 xe_mmio_read32(struct xe_gt *gt, struct xe_reg reg) 59{ 60 struct xe_tile *tile = gt_to_tile(gt); 61 62 if (reg.addr < gt->mmio.adj_limit) 63 reg.addr += gt->mmio.adj_offset; 64 65 return readl((reg.ext ? tile->mmio_ext.regs : tile->mmio.regs) + reg.addr); 66} 67 68static inline u32 xe_mmio_rmw32(struct xe_gt *gt, struct xe_reg reg, u32 clr, 69 u32 set) 70{ 71 u32 old, reg_val; 72 73 old = xe_mmio_read32(gt, reg); 74 reg_val = (old & ~clr) | set; 75 xe_mmio_write32(gt, reg, reg_val); 76 77 return old; 78} 79 80static inline int xe_mmio_write32_and_verify(struct xe_gt *gt, 81 struct xe_reg reg, u32 val, 82 u32 mask, u32 eval) 83{ 84 u32 reg_val; 85 86 xe_mmio_write32(gt, reg, val); 87 reg_val = xe_mmio_read32(gt, reg); 88 89 return (reg_val & mask) != eval ? -EINVAL : 0; 90} 91 92static inline bool xe_mmio_in_range(const struct xe_gt *gt, 93 const struct xe_mmio_range *range, 94 struct xe_reg reg) 95{ 96 if (reg.addr < gt->mmio.adj_limit) 97 reg.addr += gt->mmio.adj_offset; 98 99 return range && reg.addr >= range->start && reg.addr <= range->end; 100} 101 102int xe_mmio_probe_vram(struct xe_device *xe); 103u64 xe_mmio_read64_2x32(struct xe_gt *gt, struct xe_reg reg); 104int xe_mmio_wait32(struct xe_gt *gt, struct xe_reg reg, u32 mask, u32 val, u32 timeout_us, 105 u32 *out_val, bool atomic); 106 107#endif 108