sim: Thermal support for Linux
authorDavid Guillen Fandos <david.guillen@arm.com>
Wed, 13 May 2015 14:02:25 +0000 (15:02 +0100)
committerDavid Guillen Fandos <david.guillen@arm.com>
Wed, 13 May 2015 14:02:25 +0000 (15:02 +0100)
This patch enables Linux to read the temperature using hwmon infrastructure.
In order to use this in your gem5 you need to compile the kernel using the
following configs:

CONFIG_HWMON=y
CONFIG_SENSORS_VEXPRESS=y

And a proper dts file (containing an entry such as):

dcc {
 compatible = "arm,vexpress,config-bus";
 arm,vexpress,config-bridge = <&v2m_sysreg>;

  temp@0 {
   compatible = "arm,vexpress-temp";
   arm,vexpress-sysreg,func = <4 0>;
   label = "DCC";
  };
};

src/dev/arm/RealView.py
src/dev/arm/rv_ctrl.cc
src/dev/arm/rv_ctrl.hh

index 9d4dc6aaff51129ca5c1ead75f6ab5e12d8bdec2..17b3eb51dca742b1bb3102b1d754fa0799fc2c71 100644 (file)
@@ -129,6 +129,22 @@ class RealViewOsc(ClockDomain):
 
     freq = Param.Clock("Default frequency")
 
+class RealViewTemperatureSensor(SimObject):
+    type = 'RealViewTemperatureSensor'
+    cxx_header = "dev/arm/rv_ctrl.hh"
+
+    parent = Param.RealViewCtrl(Parent.any, "RealView controller")
+
+    system = Param.System(Parent.any, "system")
+
+    # See ARM DUI 0447J (ARM Motherboard Express uATX -- V2M-P1) and
+    # the individual core/logic tile reference manuals for details
+    # about the site/position/dcc/device allocation.
+    site = Param.UInt8("Board Site")
+    position = Param.UInt8("Position in device stack")
+    dcc = Param.UInt8("Daughterboard Configuration Controller")
+    device = Param.UInt8("Device ID")
+
 class VExpressMCC(SubSystem):
     """ARM V2M-P1 Motherboard Configuration Controller
 
@@ -140,11 +156,17 @@ Express (V2M-P1) motherboard. See ARM DUI 0447J for details.
     class Osc(RealViewOsc):
         site, position, dcc = (0, 0, 0)
 
+    class Temperature(RealViewTemperatureSensor):
+        site, position, dcc = (0, 0, 0)
+
     osc_mcc = Osc(device=0, freq="50MHz")
     osc_clcd = Osc(device=1, freq="23.75MHz")
     osc_peripheral = Osc(device=2, freq="24MHz")
     osc_system_bus = Osc(device=4, freq="24MHz")
 
+    # See Table 4.19 in ARM DUI 0447J (Motherboard Express uATX TRM).
+    temp_crtl = Temperature(device=0)
+
 class CoreTile2A15DCC(SubSystem):
     """ARM CoreTile Express A15x2 Daughterboard Configuration Controller
 
index 507def0c14a7c957f489bb5394b25cbc233fb93e..f89f23b598492e1bde908df6b9a5a080f9dac3dc 100644 (file)
  * Authors: Ali Saidi
  */
 
+#include "dev/arm/rv_ctrl.hh"
+
 #include "base/trace.hh"
 #include "debug/RVCTRL.hh"
-#include "dev/arm/rv_ctrl.hh"
 #include "mem/packet.hh"
 #include "mem/packet_access.hh"
+#include "sim/power/thermal_model.hh"
+#include "sim/system.hh"
 #include "sim/voltage_domain.hh"
 
 RealViewCtrl::RealViewCtrl(Params *p)
@@ -293,7 +296,21 @@ RealViewOsc::write(uint32_t freq)
     clockPeriod(SimClock::Float::s / freq);
 }
 
+uint32_t
+RealViewTemperatureSensor::read() const
+{
+    // Temperature reported in uC
+    ThermalModel * tm = system->getThermalModel();
+    if (tm) {
+        double t = tm->getTemp();
+        if (t < 0)
+            warn("Temperature below zero!\n");
+        return fmax(0, t) * 1000000;
+    }
 
+    // Report a dummy 25 degrees temperature
+    return 25000000;
+}
 
 RealViewCtrl *
 RealViewCtrlParams::create()
@@ -306,3 +323,9 @@ RealViewOscParams::create()
 {
     return new RealViewOsc(this);
 }
+
+RealViewTemperatureSensor *
+RealViewTemperatureSensorParams::create()
+{
+    return new RealViewTemperatureSensor(this);
+}
index 1a55025a8e63f8d0d45a143900b1e37a7f76cee0..b325c4b16ee7d8889beb674b4508cf755b73830c 100644 (file)
@@ -44,6 +44,7 @@
 #include "dev/io_device.hh"
 #include "params/RealViewCtrl.hh"
 #include "params/RealViewOsc.hh"
+#include "params/RealViewTemperatureSensor.hh"
 
 /** @file
  * This implements the simple real view registers on a PBXA9
@@ -219,5 +220,32 @@ class RealViewOsc
     void clockPeriod(Tick clock_period);
 };
 
+/**
+ * This device implements the temperature sensor used in the
+ * RealView/Versatile Express platform.
+ *
+ * See ARM DUI 0447J (ARM  Motherboard Express uATX -- V2M-P1).
+ */
+class RealViewTemperatureSensor
+    : public SimObject, RealViewCtrl::Device
+{
+  public:
+    RealViewTemperatureSensor(RealViewTemperatureSensorParams *p)
+    : SimObject(p),
+      RealViewCtrl::Device(*p->parent, RealViewCtrl::FUNC_TEMP,
+                           p->site, p->position, p->dcc, p->device),
+      system(p->system)
+    {}
+    virtual ~RealViewTemperatureSensor() {};
+
+  public: // RealViewCtrl::Device interface
+    uint32_t read() const override;
+    void write(uint32_t temp) override {}
+
+  protected:
+    /** The system this RV device belongs to */
+    System * system;
+};
+
 
 #endif // __DEV_ARM_RV_HH__