| 1 |
// Copyright 2022 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
//go:build loong64 |
| 6 |
|
| 7 |
package cpu |
| 8 |
|
| 9 |
const cacheLineSize = 64 |
| 10 |
|
| 11 |
// Bit fields for CPUCFG registers, Related reference documents: |
| 12 |
// https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_cpucfg |
| 13 |
const ( |
| 14 |
// CPUCFG1 bits |
| 15 |
cpucfg1_CRC32 = 1 << 25 |
| 16 |
|
| 17 |
// CPUCFG2 bits |
| 18 |
cpucfg2_LAM_BH = 1 << 27 |
| 19 |
cpucfg2_LAMCAS = 1 << 28 |
| 20 |
cpucfg2_LLACQ_SCREL = 1 << 29 |
| 21 |
cpucfg2_SCQ = 1 << 30 |
| 22 |
|
| 23 |
// CPUCFG3 bits |
| 24 |
cpucfg3_DBAR_HINTS = 1 << 17 |
| 25 |
) |
| 26 |
|
| 27 |
func initOptions() { |
| 28 |
options = []option{ |
| 29 |
{Name: "lsx", Feature: &Loong64.HasLSX}, |
| 30 |
{Name: "lasx", Feature: &Loong64.HasLASX}, |
| 31 |
{Name: "crc32", Feature: &Loong64.HasCRC32}, |
| 32 |
{Name: "lam_bh", Feature: &Loong64.HasLAM_BH}, |
| 33 |
{Name: "lamcas", Feature: &Loong64.HasLAMCAS}, |
| 34 |
{Name: "llacq_screl", Feature: &Loong64.HasLLACQ_SCREL}, |
| 35 |
{Name: "scq", Feature: &Loong64.HasSCQ}, |
| 36 |
{Name: "dbar_hints", Feature: &Loong64.HasDBAR_HINTS}, |
| 37 |
} |
| 38 |
|
| 39 |
// The CPUCFG data on Loong64 only reflects the hardware capabilities, |
| 40 |
// not the kernel support status, so features such as LSX and LASX that |
| 41 |
// require kernel support cannot be obtained from the CPUCFG data. |
| 42 |
// |
| 43 |
// These features only require hardware capability support and do not |
| 44 |
// require kernel specific support, so they can be obtained directly |
| 45 |
// through CPUCFG |
| 46 |
cfg1 := get_cpucfg(1) |
| 47 |
cfg2 := get_cpucfg(2) |
| 48 |
cfg3 := get_cpucfg(3) |
| 49 |
|
| 50 |
Loong64.HasCRC32 = cfgIsSet(cfg1, cpucfg1_CRC32) |
| 51 |
Loong64.HasLAMCAS = cfgIsSet(cfg2, cpucfg2_LAMCAS) |
| 52 |
Loong64.HasLAM_BH = cfgIsSet(cfg2, cpucfg2_LAM_BH) |
| 53 |
Loong64.HasLLACQ_SCREL = cfgIsSet(cfg2, cpucfg2_LLACQ_SCREL) |
| 54 |
Loong64.HasSCQ = cfgIsSet(cfg2, cpucfg2_SCQ) |
| 55 |
Loong64.HasDBAR_HINTS = cfgIsSet(cfg3, cpucfg3_DBAR_HINTS) |
| 56 |
} |
| 57 |
|
| 58 |
func get_cpucfg(reg uint32) uint32 |
| 59 |
|
| 60 |
func cfgIsSet(cfg uint32, val uint32) bool { |
| 61 |
return cfg&val != 0 |
| 62 |
} |