source: branches/reconfiguration/softs/libs/io.h @ 887

Last change on this file since 887 was 857, checked in by cfuguet, 9 years ago

reconf: modification in softs/lib/io.h header file

  • When performing an IO write with the physical address extension, restore the previous extension at the end of the function.
File size: 1.7 KB
Line 
1/**
2 * \file    io.h
3 * \date    5 September 2012
4 * \author  Cesar Fuguet
5 *
6 * Utility functions to write or read memory mapped hardware registers
7 */
8#ifndef IO_H
9#define IO_H
10
11#include <cpu.h>
12
13/**
14 * \brief Read an 32 bits memory mapped hardware register
15 *
16 * \note interrupts should be disabled while executing this function
17 */
18static inline unsigned int ioread32(uint64_t paddr)
19{
20    uint32_t value;
21    uint32_t msb = paddr >> CLUSTER_OFFSET_BITS;
22    uint32_t lsb = paddr & ((1ULL << CLUSTER_OFFSET_BITS)-1);
23
24    asm volatile("mfc2   $8,     $24   \n"  /* t0 <= DATA_PADDR_EXT  */
25                 "mtc2   %2,     $24   \n"  /* DATA_PADDR_EXT <= msb */
26                 "lw     %0,     0(%1) \n"  /* value <= *paddr       */
27                 "mtc2   $8,     $24   \n"  /* DATA_PADDR_EXT <= 0   */
28                 : "=r"(value)
29                 : "r"(lsb), "r"(msb)
30                 : "$8", "memory");
31
32    return value;
33}
34
35/**
36 * \brief Write an 32 bits memory mapped hardware register
37 *
38 * \note interrupts should be disabled while executing this function
39 */
40static inline void iowrite32(uint64_t paddr, uint32_t value)
41{
42    uint32_t msb = paddr >> CLUSTER_OFFSET_BITS;
43    uint32_t lsb = paddr & ((1ULL << CLUSTER_OFFSET_BITS)-1);
44
45    asm volatile("mfc2   $8,     $24   \n"  /* t0 <= DATA_PADDR_EXT  */
46                 "mtc2   %2,     $24   \n"  /* DATA_PADDR_EXT <= msb */
47                 "sw     %0,     0(%1) \n"  /* value <= *paddr       */
48                 "mtc2   $8,     $24   \n"  /* DATA_PADDR_EXT <= 0   */
49                 "sync                 \n"
50                 : /* no outputs */
51                 : "r"(value), "r"(lsb), "r"(msb)
52                 : "$8", "memory");
53}
54
55#endif
56
57/*
58 * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
59 */
Note: See TracBrowser for help on using the repository browser.