gem5  v22.1.0.0
speaker.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "dev/x86/speaker.hh"
30 
31 #include "base/bitunion.hh"
32 #include "base/trace.hh"
33 #include "debug/PcSpeaker.hh"
34 #include "dev/x86/i8254.hh"
35 #include "mem/packet.hh"
36 #include "mem/packet_access.hh"
37 
38 namespace gem5
39 {
40 
41 Tick
43 {
44  assert(pkt->getAddr() == pioAddr);
45  assert(pkt->getSize() == 1);
46  controlVal.timer = timer->outputHigh(2) ? 1 : 0;
47  DPRINTF(PcSpeaker,
48  "Reading from speaker device: gate %s, speaker %s, output %s.\n",
49  controlVal.gate ? "on" : "off",
50  controlVal.speaker ? "on" : "off",
51  controlVal.timer ? "on" : "off");
52  pkt->setLE((uint8_t)controlVal);
53  pkt->makeAtomicResponse();
54  return latency;
55 }
56 
57 Tick
59 {
60  assert(pkt->getAddr() == pioAddr);
61  assert(pkt->getSize() == 1);
62  SpeakerControl val = pkt->getLE<uint8_t>();
63  controlVal.gate = val.gate;
64  //Change the gate value in the timer.
65  if (!val.gate)
66  warn("The gate bit of the pc speaker isn't implemented and "
67  "is always on.\n");
68  //This would control whether the timer output is hooked up to a physical
69  //speaker. Since M5 can't make noise, it's value doesn't actually do
70  //anything.
71  controlVal.speaker = val.speaker;
72  DPRINTF(PcSpeaker, "Writing to speaker device: gate %s, speaker %s.\n",
73  controlVal.gate ? "on" : "off", controlVal.speaker ? "on" : "off");
74  pkt->makeAtomicResponse();
75  return latency;
76 }
77 
78 void
80 {
81  SERIALIZE_SCALAR(controlVal);
82 }
83 
84 void
86 {
87  UNSERIALIZE_SCALAR(controlVal);
88 }
89 
90 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:151
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Addr getAddr() const
Definition: packet.hh:805
void setLE(T v)
Set the value in the data pointer to v as little endian.
unsigned getSize() const
Definition: packet.hh:815
void makeAtomicResponse()
Definition: packet.hh:1071
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: speaker.cc:85
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: speaker.cc:42
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: speaker.cc:79
Bitfield< 5 > timer
Definition: speaker.hh:52
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: speaker.cc:58
#define warn(...)
Definition: logging.hh:246
Bitfield< 63 > val
Definition: misc.hh:776
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::ostream CheckpointOut
Definition: serialize.hh:66
uint64_t Tick
Tick count type.
Definition: types.hh:58
Declaration of the Packet class.
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:568

Generated on Wed Dec 21 2022 10:22:35 for gem5 by doxygen 1.9.1