18c2ecf20Sopenharmony_ci/***********************license start***************
28c2ecf20Sopenharmony_ci * Author: Cavium Networks
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Contact: support@caviumnetworks.com
58c2ecf20Sopenharmony_ci * This file is part of the OCTEON SDK
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (c) 2003-2008 Cavium Networks
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * This file is free software; you can redistribute it and/or modify
108c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as
118c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * This file is distributed in the hope that it will be useful, but
148c2ecf20Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
158c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
168c2ecf20Sopenharmony_ci * NONINFRINGEMENT.  See the GNU General Public License for more
178c2ecf20Sopenharmony_ci * details.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License
208c2ecf20Sopenharmony_ci * along with this file; if not, write to the Free Software
218c2ecf20Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
228c2ecf20Sopenharmony_ci * or visit http://www.gnu.org/licenses/.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * This file may also be available under a different license from Cavium.
258c2ecf20Sopenharmony_ci * Contact Cavium Networks for more information
268c2ecf20Sopenharmony_ci ***********************license end**************************************/
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/**
298c2ecf20Sopenharmony_ci *
308c2ecf20Sopenharmony_ci * This file provides support for the processor local scratch memory.
318c2ecf20Sopenharmony_ci * Scratch memory is byte addressable - all addresses are byte addresses.
328c2ecf20Sopenharmony_ci *
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifndef __CVMX_SCRATCH_H__
368c2ecf20Sopenharmony_ci#define __CVMX_SCRATCH_H__
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/*
398c2ecf20Sopenharmony_ci * Note: This define must be a long, not a long long in order to
408c2ecf20Sopenharmony_ci * compile without warnings for both 32bit and 64bit.
418c2ecf20Sopenharmony_ci */
428c2ecf20Sopenharmony_ci#define CVMX_SCRATCH_BASE	(-32768l)	/* 0xffffffffffff8000 */
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/**
458c2ecf20Sopenharmony_ci * Reads an 8 bit value from the processor local scratchpad memory.
468c2ecf20Sopenharmony_ci *
478c2ecf20Sopenharmony_ci * @address: byte address to read from
488c2ecf20Sopenharmony_ci *
498c2ecf20Sopenharmony_ci * Returns value read
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_cistatic inline uint8_t cvmx_scratch_read8(uint64_t address)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	return *CASTPTR(volatile uint8_t, CVMX_SCRATCH_BASE + address);
548c2ecf20Sopenharmony_ci}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/**
578c2ecf20Sopenharmony_ci * Reads a 16 bit value from the processor local scratchpad memory.
588c2ecf20Sopenharmony_ci *
598c2ecf20Sopenharmony_ci * @address: byte address to read from
608c2ecf20Sopenharmony_ci *
618c2ecf20Sopenharmony_ci * Returns value read
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_cistatic inline uint16_t cvmx_scratch_read16(uint64_t address)
648c2ecf20Sopenharmony_ci{
658c2ecf20Sopenharmony_ci	return *CASTPTR(volatile uint16_t, CVMX_SCRATCH_BASE + address);
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/**
698c2ecf20Sopenharmony_ci * Reads a 32 bit value from the processor local scratchpad memory.
708c2ecf20Sopenharmony_ci *
718c2ecf20Sopenharmony_ci * @address: byte address to read from
728c2ecf20Sopenharmony_ci *
738c2ecf20Sopenharmony_ci * Returns value read
748c2ecf20Sopenharmony_ci */
758c2ecf20Sopenharmony_cistatic inline uint32_t cvmx_scratch_read32(uint64_t address)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	return *CASTPTR(volatile uint32_t, CVMX_SCRATCH_BASE + address);
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/**
818c2ecf20Sopenharmony_ci * Reads a 64 bit value from the processor local scratchpad memory.
828c2ecf20Sopenharmony_ci *
838c2ecf20Sopenharmony_ci * @address: byte address to read from
848c2ecf20Sopenharmony_ci *
858c2ecf20Sopenharmony_ci * Returns value read
868c2ecf20Sopenharmony_ci */
878c2ecf20Sopenharmony_cistatic inline uint64_t cvmx_scratch_read64(uint64_t address)
888c2ecf20Sopenharmony_ci{
898c2ecf20Sopenharmony_ci	return *CASTPTR(volatile uint64_t, CVMX_SCRATCH_BASE + address);
908c2ecf20Sopenharmony_ci}
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/**
938c2ecf20Sopenharmony_ci * Writes an 8 bit value to the processor local scratchpad memory.
948c2ecf20Sopenharmony_ci *
958c2ecf20Sopenharmony_ci * @address: byte address to write to
968c2ecf20Sopenharmony_ci * @value:   value to write
978c2ecf20Sopenharmony_ci */
988c2ecf20Sopenharmony_cistatic inline void cvmx_scratch_write8(uint64_t address, uint64_t value)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	*CASTPTR(volatile uint8_t, CVMX_SCRATCH_BASE + address) =
1018c2ecf20Sopenharmony_ci	    (uint8_t) value;
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/**
1058c2ecf20Sopenharmony_ci * Writes a 32 bit value to the processor local scratchpad memory.
1068c2ecf20Sopenharmony_ci *
1078c2ecf20Sopenharmony_ci * @address: byte address to write to
1088c2ecf20Sopenharmony_ci * @value:   value to write
1098c2ecf20Sopenharmony_ci */
1108c2ecf20Sopenharmony_cistatic inline void cvmx_scratch_write16(uint64_t address, uint64_t value)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	*CASTPTR(volatile uint16_t, CVMX_SCRATCH_BASE + address) =
1138c2ecf20Sopenharmony_ci	    (uint16_t) value;
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/**
1178c2ecf20Sopenharmony_ci * Writes a 16 bit value to the processor local scratchpad memory.
1188c2ecf20Sopenharmony_ci *
1198c2ecf20Sopenharmony_ci * @address: byte address to write to
1208c2ecf20Sopenharmony_ci * @value:   value to write
1218c2ecf20Sopenharmony_ci */
1228c2ecf20Sopenharmony_cistatic inline void cvmx_scratch_write32(uint64_t address, uint64_t value)
1238c2ecf20Sopenharmony_ci{
1248c2ecf20Sopenharmony_ci	*CASTPTR(volatile uint32_t, CVMX_SCRATCH_BASE + address) =
1258c2ecf20Sopenharmony_ci	    (uint32_t) value;
1268c2ecf20Sopenharmony_ci}
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/**
1298c2ecf20Sopenharmony_ci * Writes a 64 bit value to the processor local scratchpad memory.
1308c2ecf20Sopenharmony_ci *
1318c2ecf20Sopenharmony_ci * @address: byte address to write to
1328c2ecf20Sopenharmony_ci * @value:   value to write
1338c2ecf20Sopenharmony_ci */
1348c2ecf20Sopenharmony_cistatic inline void cvmx_scratch_write64(uint64_t address, uint64_t value)
1358c2ecf20Sopenharmony_ci{
1368c2ecf20Sopenharmony_ci	*CASTPTR(volatile uint64_t, CVMX_SCRATCH_BASE + address) = value;
1378c2ecf20Sopenharmony_ci}
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#endif /* __CVMX_SCRATCH_H__ */
140