Path: blob/master/arch/powerpc/include/asm/dcr-native.h
15117 views
/*1* (c) Copyright 2006 Benjamin Herrenschmidt, IBM Corp.2* <[email protected]>3*4* This program is free software; you can redistribute it and/or modify5* it under the terms of the GNU General Public License as published by6* the Free Software Foundation; either version 2 of the License, or7* (at your option) any later version.8*9* This program is distributed in the hope that it will be useful,10* but WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See12* the GNU General Public License for more details.13*14* You should have received a copy of the GNU General Public License15* along with this program; if not, write to the Free Software16* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA17*/1819#ifndef _ASM_POWERPC_DCR_NATIVE_H20#define _ASM_POWERPC_DCR_NATIVE_H21#ifdef __KERNEL__22#ifndef __ASSEMBLY__2324#include <linux/spinlock.h>25#include <asm/cputable.h>2627typedef struct {28unsigned int base;29} dcr_host_native_t;3031static inline bool dcr_map_ok_native(dcr_host_native_t host)32{33return 1;34}3536#define dcr_map_native(dev, dcr_n, dcr_c) \37((dcr_host_native_t){ .base = (dcr_n) })38#define dcr_unmap_native(host, dcr_c) do {} while (0)39#define dcr_read_native(host, dcr_n) mfdcr(dcr_n + host.base)40#define dcr_write_native(host, dcr_n, value) mtdcr(dcr_n + host.base, value)4142/* Table based DCR accessors */43extern void __mtdcr(unsigned int reg, unsigned int val);44extern unsigned int __mfdcr(unsigned int reg);4546/* mfdcrx/mtdcrx instruction based accessors. We hand code47* the opcodes in order not to depend on newer binutils48*/49static inline unsigned int mfdcrx(unsigned int reg)50{51unsigned int ret;52asm volatile(".long 0x7c000206 | (%0 << 21) | (%1 << 16)"53: "=r" (ret) : "r" (reg));54return ret;55}5657static inline void mtdcrx(unsigned int reg, unsigned int val)58{59asm volatile(".long 0x7c000306 | (%0 << 21) | (%1 << 16)"60: : "r" (val), "r" (reg));61}6263#define mfdcr(rn) \64({unsigned int rval; \65if (__builtin_constant_p(rn) && rn < 1024) \66asm volatile("mfdcr %0," __stringify(rn) \67: "=r" (rval)); \68else if (likely(cpu_has_feature(CPU_FTR_INDEXED_DCR))) \69rval = mfdcrx(rn); \70else \71rval = __mfdcr(rn); \72rval;})7374#define mtdcr(rn, v) \75do { \76if (__builtin_constant_p(rn) && rn < 1024) \77asm volatile("mtdcr " __stringify(rn) ",%0" \78: : "r" (v)); \79else if (likely(cpu_has_feature(CPU_FTR_INDEXED_DCR))) \80mtdcrx(rn, v); \81else \82__mtdcr(rn, v); \83} while (0)8485/* R/W of indirect DCRs make use of standard naming conventions for DCRs */86extern spinlock_t dcr_ind_lock;8788static inline unsigned __mfdcri(int base_addr, int base_data, int reg)89{90unsigned long flags;91unsigned int val;9293spin_lock_irqsave(&dcr_ind_lock, flags);94if (cpu_has_feature(CPU_FTR_INDEXED_DCR)) {95mtdcrx(base_addr, reg);96val = mfdcrx(base_data);97} else {98__mtdcr(base_addr, reg);99val = __mfdcr(base_data);100}101spin_unlock_irqrestore(&dcr_ind_lock, flags);102return val;103}104105static inline void __mtdcri(int base_addr, int base_data, int reg,106unsigned val)107{108unsigned long flags;109110spin_lock_irqsave(&dcr_ind_lock, flags);111if (cpu_has_feature(CPU_FTR_INDEXED_DCR)) {112mtdcrx(base_addr, reg);113mtdcrx(base_data, val);114} else {115__mtdcr(base_addr, reg);116__mtdcr(base_data, val);117}118spin_unlock_irqrestore(&dcr_ind_lock, flags);119}120121static inline void __dcri_clrset(int base_addr, int base_data, int reg,122unsigned clr, unsigned set)123{124unsigned long flags;125unsigned int val;126127spin_lock_irqsave(&dcr_ind_lock, flags);128if (cpu_has_feature(CPU_FTR_INDEXED_DCR)) {129mtdcrx(base_addr, reg);130val = (mfdcrx(base_data) & ~clr) | set;131mtdcrx(base_data, val);132} else {133__mtdcr(base_addr, reg);134val = (__mfdcr(base_data) & ~clr) | set;135__mtdcr(base_data, val);136}137spin_unlock_irqrestore(&dcr_ind_lock, flags);138}139140#define mfdcri(base, reg) __mfdcri(DCRN_ ## base ## _CONFIG_ADDR, \141DCRN_ ## base ## _CONFIG_DATA, \142reg)143144#define mtdcri(base, reg, data) __mtdcri(DCRN_ ## base ## _CONFIG_ADDR, \145DCRN_ ## base ## _CONFIG_DATA, \146reg, data)147148#define dcri_clrset(base, reg, clr, set) __dcri_clrset(DCRN_ ## base ## _CONFIG_ADDR, \149DCRN_ ## base ## _CONFIG_DATA, \150reg, clr, set)151152#endif /* __ASSEMBLY__ */153#endif /* __KERNEL__ */154#endif /* _ASM_POWERPC_DCR_NATIVE_H */155156157