github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/cmds/core/io/smn.go (about) 1 // Copyright 2020 the u-root 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 amd64 && linux 6 // +build amd64,linux 7 8 // The System Management Network (SMN, try to say it fast) 9 // is a parallel universe address space on newer AMD64 cpus. 10 // The address is 32 bits, as is data. 11 // Unfortunately it is only accessible via the classic 12 // index/register pair. Fortunately that pair is accessible 13 // in mmconfig space. 14 package main 15 16 import ( 17 "github.com/mvdan/u-root-coreutils/pkg/memio" 18 ) 19 20 type op func() error 21 22 // This is a const at present but there are no guarantees. 23 const pcibase = 0xe0000000 24 25 func init() { 26 usageMsg += `io rs index # read from system management network on newer AMD CPUs. 27 io ws index value # write value to system management network on newer AMD CPUs. 28 ` 29 addCmd(readCmds, "rs", &cmd{smnRead, 32, 32}) 30 addCmd(writeCmds, "ws", &cmd{smnWrite, 32, 32}) 31 } 32 33 func do(addr int64, data memio.UintN, op func(int64, memio.UintN) error) error { 34 a := newInt(uint64(addr), 32) 35 if err := memio.Write(pcibase+0xb8, a); err != nil { 36 return err 37 } 38 return op(pcibase+0xbc, data) 39 } 40 41 func smnWrite(addr int64, data memio.UintN) error { 42 return do(addr, data, memio.Write) 43 } 44 45 func smnRead(addr int64, data memio.UintN) error { 46 return do(addr, data, memio.Read) 47 }