162306a36Sopenharmony_ci/***********************license start*************** 262306a36Sopenharmony_ci * Author: Cavium Networks 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Contact: support@caviumnetworks.com 562306a36Sopenharmony_ci * This file is part of the OCTEON SDK 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Copyright (c) 2003-2008 Cavium Networks 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * This file is free software; you can redistribute it and/or modify 1062306a36Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as 1162306a36Sopenharmony_ci * published by the Free Software Foundation. 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * This file is distributed in the hope that it will be useful, but 1462306a36Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty 1562306a36Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or 1662306a36Sopenharmony_ci * NONINFRINGEMENT. See the GNU General Public License for more 1762306a36Sopenharmony_ci * details. 1862306a36Sopenharmony_ci * 1962306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License 2062306a36Sopenharmony_ci * along with this file; if not, write to the Free Software 2162306a36Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 2262306a36Sopenharmony_ci * or visit http://www.gnu.org/licenses/. 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * This file may also be available under a different license from Cavium. 2562306a36Sopenharmony_ci * Contact Cavium Networks for more information 2662306a36Sopenharmony_ci ***********************license end**************************************/ 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci/** 2962306a36Sopenharmony_ci * 3062306a36Sopenharmony_ci * This file provides support for the processor local scratch memory. 3162306a36Sopenharmony_ci * Scratch memory is byte addressable - all addresses are byte addresses. 3262306a36Sopenharmony_ci * 3362306a36Sopenharmony_ci */ 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#ifndef __CVMX_SCRATCH_H__ 3662306a36Sopenharmony_ci#define __CVMX_SCRATCH_H__ 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci/* 3962306a36Sopenharmony_ci * Note: This define must be a long, not a long long in order to 4062306a36Sopenharmony_ci * compile without warnings for both 32bit and 64bit. 4162306a36Sopenharmony_ci */ 4262306a36Sopenharmony_ci#define CVMX_SCRATCH_BASE (-32768l) /* 0xffffffffffff8000 */ 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci/** 4562306a36Sopenharmony_ci * Reads an 8 bit value from the processor local scratchpad memory. 4662306a36Sopenharmony_ci * 4762306a36Sopenharmony_ci * @address: byte address to read from 4862306a36Sopenharmony_ci * 4962306a36Sopenharmony_ci * Returns value read 5062306a36Sopenharmony_ci */ 5162306a36Sopenharmony_cistatic inline uint8_t cvmx_scratch_read8(uint64_t address) 5262306a36Sopenharmony_ci{ 5362306a36Sopenharmony_ci return *CASTPTR(volatile uint8_t, CVMX_SCRATCH_BASE + address); 5462306a36Sopenharmony_ci} 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci/** 5762306a36Sopenharmony_ci * Reads a 16 bit value from the processor local scratchpad memory. 5862306a36Sopenharmony_ci * 5962306a36Sopenharmony_ci * @address: byte address to read from 6062306a36Sopenharmony_ci * 6162306a36Sopenharmony_ci * Returns value read 6262306a36Sopenharmony_ci */ 6362306a36Sopenharmony_cistatic inline uint16_t cvmx_scratch_read16(uint64_t address) 6462306a36Sopenharmony_ci{ 6562306a36Sopenharmony_ci return *CASTPTR(volatile uint16_t, CVMX_SCRATCH_BASE + address); 6662306a36Sopenharmony_ci} 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci/** 6962306a36Sopenharmony_ci * Reads a 32 bit value from the processor local scratchpad memory. 7062306a36Sopenharmony_ci * 7162306a36Sopenharmony_ci * @address: byte address to read from 7262306a36Sopenharmony_ci * 7362306a36Sopenharmony_ci * Returns value read 7462306a36Sopenharmony_ci */ 7562306a36Sopenharmony_cistatic inline uint32_t cvmx_scratch_read32(uint64_t address) 7662306a36Sopenharmony_ci{ 7762306a36Sopenharmony_ci return *CASTPTR(volatile uint32_t, CVMX_SCRATCH_BASE + address); 7862306a36Sopenharmony_ci} 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci/** 8162306a36Sopenharmony_ci * Reads a 64 bit value from the processor local scratchpad memory. 8262306a36Sopenharmony_ci * 8362306a36Sopenharmony_ci * @address: byte address to read from 8462306a36Sopenharmony_ci * 8562306a36Sopenharmony_ci * Returns value read 8662306a36Sopenharmony_ci */ 8762306a36Sopenharmony_cistatic inline uint64_t cvmx_scratch_read64(uint64_t address) 8862306a36Sopenharmony_ci{ 8962306a36Sopenharmony_ci return *CASTPTR(volatile uint64_t, CVMX_SCRATCH_BASE + address); 9062306a36Sopenharmony_ci} 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci/** 9362306a36Sopenharmony_ci * Writes an 8 bit value to the processor local scratchpad memory. 9462306a36Sopenharmony_ci * 9562306a36Sopenharmony_ci * @address: byte address to write to 9662306a36Sopenharmony_ci * @value: value to write 9762306a36Sopenharmony_ci */ 9862306a36Sopenharmony_cistatic inline void cvmx_scratch_write8(uint64_t address, uint64_t value) 9962306a36Sopenharmony_ci{ 10062306a36Sopenharmony_ci *CASTPTR(volatile uint8_t, CVMX_SCRATCH_BASE + address) = 10162306a36Sopenharmony_ci (uint8_t) value; 10262306a36Sopenharmony_ci} 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci/** 10562306a36Sopenharmony_ci * Writes a 32 bit value to the processor local scratchpad memory. 10662306a36Sopenharmony_ci * 10762306a36Sopenharmony_ci * @address: byte address to write to 10862306a36Sopenharmony_ci * @value: value to write 10962306a36Sopenharmony_ci */ 11062306a36Sopenharmony_cistatic inline void cvmx_scratch_write16(uint64_t address, uint64_t value) 11162306a36Sopenharmony_ci{ 11262306a36Sopenharmony_ci *CASTPTR(volatile uint16_t, CVMX_SCRATCH_BASE + address) = 11362306a36Sopenharmony_ci (uint16_t) value; 11462306a36Sopenharmony_ci} 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci/** 11762306a36Sopenharmony_ci * Writes a 16 bit value to the processor local scratchpad memory. 11862306a36Sopenharmony_ci * 11962306a36Sopenharmony_ci * @address: byte address to write to 12062306a36Sopenharmony_ci * @value: value to write 12162306a36Sopenharmony_ci */ 12262306a36Sopenharmony_cistatic inline void cvmx_scratch_write32(uint64_t address, uint64_t value) 12362306a36Sopenharmony_ci{ 12462306a36Sopenharmony_ci *CASTPTR(volatile uint32_t, CVMX_SCRATCH_BASE + address) = 12562306a36Sopenharmony_ci (uint32_t) value; 12662306a36Sopenharmony_ci} 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci/** 12962306a36Sopenharmony_ci * Writes a 64 bit value to the processor local scratchpad memory. 13062306a36Sopenharmony_ci * 13162306a36Sopenharmony_ci * @address: byte address to write to 13262306a36Sopenharmony_ci * @value: value to write 13362306a36Sopenharmony_ci */ 13462306a36Sopenharmony_cistatic inline void cvmx_scratch_write64(uint64_t address, uint64_t value) 13562306a36Sopenharmony_ci{ 13662306a36Sopenharmony_ci *CASTPTR(volatile uint64_t, CVMX_SCRATCH_BASE + address) = value; 13762306a36Sopenharmony_ci} 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci#endif /* __CVMX_SCRATCH_H__ */ 140