geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
SSTIOImp.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef SSTIOIMP_HPP_INCLUDE
7 #define SSTIOIMP_HPP_INCLUDE
8 
9 #include <algorithm>
10 #include <cstdint>
11 #include <map>
12 #include <memory>
13 #include <string>
14 #include <type_traits>
15 
16 #include "SSTIO.hpp"
17 
18 namespace geopm
19 {
20  class SSTIoctl;
21  struct sst_mbox_interface_batch_s;
22  struct sst_mmio_interface_batch_s;
23  class SSTIOImp : public SSTIO
24  {
25  public:
29  SSTIOImp(uint32_t max_cpus);
30 
33  SSTIOImp(uint32_t max_cpus, std::shared_ptr<SSTIoctl> ioctl_interface);
34 
35  virtual ~SSTIOImp() = default;
36 
38  int add_mbox_read(uint32_t cpu_index, uint16_t command,
39  uint16_t subcommand, uint32_t subcommand_arg) override;
40  int add_mbox_write(uint32_t cpu_index, uint16_t command,
41  uint16_t subcommand, uint32_t interface_parameter,
42  uint16_t read_subcommand,
43  uint32_t read_interface_parameter,
44  uint32_t read_mask) override;
45  int add_mmio_read(uint32_t cpu_index, uint16_t register_offset) override;
46  int add_mmio_write(uint32_t cpu_index, uint16_t register_offset,
47  uint32_t register_value, uint32_t read_mask) override;
48  // call ioctl() for both mbox list and mmio list,
49  // unless we end up splitting this class
50  void read_batch(void) override;
51 
52  uint64_t sample(int batch_idx) const override;
53  void write_batch(void) override;
54  uint32_t read_mbox_once(uint32_t cpu_index, uint16_t command,
55  uint16_t subcommand, uint32_t subcommand_arg) override;
56  void write_mbox_once(uint32_t cpu_index, uint16_t command,
57  uint16_t subcommand, uint32_t interface_parameter,
58  uint16_t read_subcommand,
59  uint32_t read_interface_parameter,
60  uint32_t read_mask, uint64_t write_value,
61  uint64_t write_mask) override;
62  uint32_t read_mmio_once(uint32_t cpu_index, uint16_t register_offset) override;
63  void write_mmio_once(uint32_t cpu_index, uint16_t register_offset,
64  uint32_t register_value, uint32_t read_mask,
65  uint64_t write_value, uint64_t write_mask) override;
66  void adjust(int batch_idx, uint64_t write_value, uint64_t write_mask) override;
67  uint32_t get_punit_from_cpu(uint32_t cpu_index) override;
68 
69  private:
70  enum message_type_e
71  {
72  MBOX,
73  MMIO
74  };
75 
76  template<typename OuterStruct>
77  using InnerStruct =
78  typename std::remove_all_extents<decltype(OuterStruct::interfaces)>::type;
79 
80  // Given a single vector of messages to send to an ioctl, split it
81  // into multiple structs to send to that ioctl. Each InnerStruct
82  // contains a single message. Each OuterStruct contains multiple
83  // messages, with size upper-bounded by m_batch_command_limit.
84  template<typename OuterStruct>
85  std::vector<std::unique_ptr<OuterStruct, void (*)(OuterStruct *)> >
86  ioctl_structs_from_vector(const std::vector<InnerStruct<OuterStruct> > &commands)
87 
88  {
89  std::vector<std::unique_ptr<OuterStruct, void (*)(OuterStruct *)> > outer_structs;
90 
91  size_t handled_commands = 0;
92  while (handled_commands < commands.size())
93  {
94  size_t batch_size = std::min(
95  static_cast<size_t>(m_batch_command_limit),
96  commands.size() - handled_commands);
97 
98  // The inner struct is embedded in the outer struct, and
99  // the inner struct's size depends on how many entries it
100  // can contain. That size is dynamically determined, so we
101  // manually allocate the outer struct here.
102  outer_structs.emplace_back(reinterpret_cast<OuterStruct *>(
103  new char[sizeof(OuterStruct::num_entries) +
104  sizeof(InnerStruct<OuterStruct>) * commands.size()]),
105  [](OuterStruct *outer_struct) {
106  delete[] reinterpret_cast<char *>(outer_struct);
107  });
108  outer_structs.back()->num_entries = batch_size;
109  std::copy(commands.data() + handled_commands,
110  commands.data() + handled_commands + batch_size,
111  outer_structs.back()->interfaces);
112 
113  handled_commands += batch_size;
114  }
115 
116  return outer_structs;
117  }
118 
119  std::shared_ptr<SSTIoctl> m_ioctl;
120  int m_batch_command_limit;
121  std::vector<struct sst_mbox_interface_s> m_mbox_read_interfaces;
122  std::vector<struct sst_mbox_interface_s> m_mbox_write_interfaces;
123  std::vector<struct sst_mbox_interface_s> m_mbox_rmw_interfaces;
124  std::vector<uint32_t> m_mbox_rmw_read_masks;
125  std::vector<uint32_t> m_mbox_rmw_write_masks;
126  std::vector<struct sst_mmio_interface_s> m_mmio_read_interfaces;
127  std::vector<struct sst_mmio_interface_s> m_mmio_write_interfaces;
128  std::vector<struct sst_mmio_interface_s> m_mmio_rmw_interfaces;
129  std::vector<uint32_t> m_mmio_rmw_read_masks;
130  std::vector<uint32_t> m_mmio_rmw_write_masks;
131  std::vector<std::pair<message_type_e, size_t> > m_added_interfaces;
132  std::vector<std::unique_ptr<sst_mbox_interface_batch_s, void(*)(sst_mbox_interface_batch_s*)> > m_mbox_read_batch;
133  std::vector<std::unique_ptr<sst_mbox_interface_batch_s, void(*)(sst_mbox_interface_batch_s*)> > m_mbox_write_batch;
134  std::vector<std::unique_ptr<sst_mmio_interface_batch_s, void(*)(sst_mmio_interface_batch_s*)> > m_mmio_read_batch;
135  std::vector<std::unique_ptr<sst_mmio_interface_batch_s, void(*)(sst_mmio_interface_batch_s*)> > m_mmio_write_batch;
136  std::map<uint32_t, uint32_t> m_cpu_punit_core_map;
137  };
138 }
139 
140 #endif
Definition: SSTIO.hpp:17
Definition: SSTIOImp.hpp:24
void write_mmio_once(uint32_t cpu_index, uint16_t register_offset, uint32_t register_value, uint32_t read_mask, uint64_t write_value, uint64_t write_mask) override
Immediately write a value to the SST MMIO interface.
Definition: SSTIO.cpp:476
void write_batch(void) override
Issue a batch write.
Definition: SSTIO.cpp:296
uint32_t read_mbox_once(uint32_t cpu_index, uint16_t command, uint16_t subcommand, uint32_t subcommand_arg) override
Immediately query the SST mailbox for a read operation.
Definition: SSTIO.cpp:387
SSTIOImp(uint32_t max_cpus)
Main constructor for the SST ioctl interface.
Definition: SSTIO.cpp:26
uint64_t sample(int batch_idx) const override
Sample a value from the most recent batch read.
Definition: SSTIO.cpp:270
int add_mbox_write(uint32_t cpu_index, uint16_t command, uint16_t subcommand, uint32_t interface_parameter, uint16_t read_subcommand, uint32_t read_interface_parameter, uint32_t read_mask) override
Interact with the mailbox on commands that are not expected to return data.
Definition: SSTIO.cpp:137
int add_mbox_read(uint32_t cpu_index, uint16_t command, uint16_t subcommand, uint32_t subcommand_arg) override
Interact with the mailbox on commands that are expected to return data.
Definition: SSTIO.cpp:80
int add_mmio_read(uint32_t cpu_index, uint16_t register_offset) override
Interact with the mmio interface on commands that are expected to return data.
Definition: SSTIO.cpp:199
virtual ~SSTIOImp()=default
int add_mmio_write(uint32_t cpu_index, uint16_t register_offset, uint32_t register_value, uint32_t read_mask) override
Interact with the mmio interface on commands that are not expected to return data.
Definition: SSTIO.cpp:215
void write_mbox_once(uint32_t cpu_index, uint16_t command, uint16_t subcommand, uint32_t interface_parameter, uint16_t read_subcommand, uint32_t read_interface_parameter, uint32_t read_mask, uint64_t write_value, uint64_t write_mask) override
Immediately query the SST mailbox for a write operation.
Definition: SSTIO.cpp:414
void read_batch(void) override
Issue a batch read.
Definition: SSTIO.cpp:237
uint32_t read_mmio_once(uint32_t cpu_index, uint16_t register_offset) override
Immediately read a value from the SST MMIO interface.
Definition: SSTIO.cpp:457
void adjust(int batch_idx, uint64_t write_value, uint64_t write_mask) override
Adjust a value for the next batch write.
Definition: SSTIO.cpp:505
uint32_t get_punit_from_cpu(uint32_t cpu_index) override
Get the punit index associated with a CPU index.
Definition: SSTIO.cpp:525
Definition: Agg.cpp:20