1 #ifndef __CB_BDK_NUMA_H__
2 #define __CB_BDK_NUMA_H__
3
4 /***********************license start***********************************
5 * Copyright (c) 2003-2017 Cavium Inc. ([email protected]). All rights
6 * reserved.
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
11 * met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * * Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials provided
19 * with the distribution.
20 *
21 * * Neither the name of Cavium Inc. nor the names of
22 * its contributors may be used to endorse or promote products
23 * derived from this software without specific prior written
24 * permission.
25 *
26 * This Software, including technical data, may be subject to U.S. export
27 * control laws, including the U.S. Export Administration Act and its
28 * associated regulations, and may be subject to export or import
29 * regulations in other countries.
30 *
31 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
32 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
33 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
34 * TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
35 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
36 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
37 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
38 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
39 * QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
40 * ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
41 ***********************license end**************************************/
42
43 /* FIXME(dhendricks): added */
44 #include <libbdk-arch/bdk-asm.h>
45 #include <libbdk-arch/bdk-model.h>
46
47 /**
48 * @file
49 *
50 * Functions for dealing with multiple chips organized into a
51 * NUMA cluster.
52 *
53 * <hr>$Revision: 49448 $<hr>
54 */
55
56 typedef enum
57 {
58 BDK_NODE_0 = 0,
59 BDK_NODE_1 = 1,
60 BDK_NODE_2 = 2,
61 BDK_NODE_3 = 3,
62 BDK_NUMA_MAX_NODES = 4
63 } bdk_node_t;
64
65 /**
66 * Return the local node number
67 *
68 * @return Node number
69 */
70 static inline bdk_node_t bdk_numa_local(void) __attribute__ ((always_inline, pure));
bdk_numa_local(void)71 static inline bdk_node_t bdk_numa_local(void)
72 {
73 #ifndef BDK_BUILD_HOST
74 int mpidr_el1;
75 BDK_MRS_NV(MPIDR_EL1, mpidr_el1);
76 int result;
77 result = (mpidr_el1 >> 16) & 0xff;
78 return BDK_NODE_0 + result;
79 #else
80 return BDK_NODE_0; /* FIXME: choose remote node */
81 #endif
82 }
83
84 /**
85 * Return the master node number
86 *
87 * @return Node number
88 */
bdk_numa_master(void)89 static inline bdk_node_t bdk_numa_master(void)
90 {
91 extern int __bdk_numa_master_node;
92 return __bdk_numa_master_node;
93 }
94
95 /**
96 * Get a bitmask of the nodes that exist
97 *
98 * @return bitmask
99 */
100 extern uint64_t bdk_numa_get_exists_mask(void);
101
102 /**
103 * Add a node to the exists mask
104 *
105 * @param node Node to add
106 */
107 extern void bdk_numa_set_exists(bdk_node_t node);
108
109 /**
110 * Return true if a node exists
111 *
112 * @param node Node to check
113 *
114 * @return Non zero if the node exists
115 */
116 extern int bdk_numa_exists(bdk_node_t node);
117
118 /**
119 * Return true if there is only one node
120 *
121 * @return
122 */
123 extern int bdk_numa_is_only_one(void);
124
125 /**
126 * Given a physical address without a node, return the proper physical address
127 * for the given node.
128 *
129 * @param node Node to create address for
130 * @param pa Base physical address
131 *
132 * @return Node specific address
133 */
134 static inline uint64_t bdk_numa_get_address(bdk_node_t node, uint64_t pa) __attribute__((pure,always_inline));
bdk_numa_get_address(bdk_node_t node,uint64_t pa)135 static inline uint64_t bdk_numa_get_address(bdk_node_t node, uint64_t pa)
136 {
137 if (pa & (1ull << 47))
138 pa |= (uint64_t)(node&3) << 44;
139 else if (CAVIUM_IS_MODEL(CAVIUM_CN8XXX))
140 pa |= (uint64_t)(node & 3) << 40; /* CN8XXX uses bits [41:40] for nodes */
141 else
142 pa |= (uint64_t)(node & 3) << 44; /* CN9XXX uses bits [45:44] for nodes */
143 return pa;
144 }
145
146 #endif
147