-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathplatform_regs.h
More file actions
145 lines (131 loc) · 5.15 KB
/
platform_regs.h
File metadata and controls
145 lines (131 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright (c) PyPTO Contributors.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
* -----------------------------------------------------------------------------------------------------------
*/
/**
* @file platform_regs.h
* @brief Platform-level register access interface for AICPU
*
* Provides unified interface for:
* 1. Platform register base address management (set/get_platform_regs)
* 2. Register read/write operations (read_reg/write_reg)
*
* The platform layer calls set_platform_regs() before aicpu_execute(),
* and runtime code calls get_platform_regs() and read_reg/write_reg()
* for register communication with AICore.
*
* Implementation: src/platform/src/aicpu/platform_regs.cpp (shared across all platforms)
*/
#ifndef PLATFORM_AICPU_PLATFORM_REGS_H_
#define PLATFORM_AICPU_PLATFORM_REGS_H_
#include <cstdint>
#include <cstddef>
#include "common/platform_config.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Set the platform register base address array.
* Called by the platform layer before aicpu_execute().
*
* @param regs Pointer (as uint64_t) to per-core register base address array
*/
void set_platform_regs(uint64_t regs);
/**
* Get the platform register base address array.
* Called by runtime AICPU executor code that needs register access.
*
* @return Pointer (as uint64_t) to per-core register base address array
*/
uint64_t get_platform_regs();
#ifdef __cplusplus
}
#endif
/**
* Read a register value from an AICore's register block
*
* @param reg_base_addr Base address of the AICore's register block
* @param reg Register identifier (C++ enum class)
* @return Register value (zero-extended to uint64_t)
*/
uint64_t read_reg(uint64_t reg_base_addr, RegId reg);
/**
* Poll a register value without memory barriers (for hot polling loops)
*
* Unlike read_reg(), this function performs a bare volatile read with no
* memory barriers. This is safe for polling loops where the "not-yet-done"
* fast path has no Normal-memory data dependency on the register value.
*
* Callers MUST insert an explicit memory barrier (e.g. poll_acquire_barrier())
* after detecting the awaited condition, before accessing Normal memory that
* depends on the polled result.
*
* On real hardware: MMIO is Device memory; volatile alone prevents caching
* and compiler reordering. No hardware barrier needed for visibility.
*
* On simulation: registers are Normal memory; volatile prevents compiler
* reordering. Cache coherence ensures cross-thread visibility within
* a bounded number of iterations.
*
* @param reg_base_addr Base address of the AICore's register block
* @param reg Register identifier (C++ enum class)
* @return Register value (zero-extended to uint64_t)
*/
uint64_t poll_reg(uint64_t reg_base_addr, RegId reg);
/**
* Write a value to an AICore's register
*
* @param reg_base_addr Base address of the AICore's register block
* @param reg Register identifier (C++ enum class)
* @param value Value to write (truncated to register width)
*/
void write_reg(uint64_t reg_base_addr, RegId reg, uint64_t value);
/**
* Initialize AICore registers after core discovery
*
* This function performs platform-agnostic register initialization that works
* for both a2a3 and a2a3sim, including enabling fast path control and clearing
* dispatch registers.
*
* @param reg_addr Register base address of the AICore
*/
void platform_init_aicore_regs(uint64_t reg_addr);
/**
* Deinitialize AICore registers before termination
*
* This function sends exit signal and closes fast path control.
*
* @param reg_addr Register base address of the AICore
*/
void platform_deinit_aicore_regs(uint64_t reg_addr);
/**
* Get physical core count for current platform
*
* This function returns the maximum valid physical_core_id value (exclusive upper bound).
* Used for validating physical_core_id from AICore handshake before using as array index.
*
* @return Physical core count (exclusive upper bound)
*/
uint32_t platform_get_physical_cores_count();
/**
* Invalidate data cache for a memory range.
*
* On ARM64 AICPU, DMA writes from the host (rtMemcpy) go directly to HBM
* without invalidating the AICPU's data cache. When rtMalloc returns the
* same device address across rounds, the AICPU may read stale cached data
* instead of the fresh values written by the host.
*
* On real hardware (onboard): performs DC CIVAC per cache line + DSB/ISB.
* On simulation (sim): no-op.
*
* @param addr Start address of the memory range
* @param size Size of the memory range in bytes
*/
void cache_invalidate_range(const void *addr, size_t size);
#endif // PLATFORM_AICPU_PLATFORM_REGS_H_