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 * Authors: Gabe Black
29 */
30
31#include "dev/x86/speaker.hh"
32
33#include "base/bitunion.hh"
34#include "base/trace.hh"
35#include "debug/PcSpeaker.hh"
36#include "dev/x86/i8254.hh"
37#include "mem/packet.hh"
38#include "mem/packet_access.hh"
39
40Tick
41X86ISA::Speaker::read(PacketPtr pkt)
42{
43    assert(pkt->getAddr() == pioAddr);
44    assert(pkt->getSize() == 1);
45    controlVal.timer = timer->outputHigh(2) ? 1 : 0;
46    DPRINTF(PcSpeaker,
47            "Reading from speaker device: gate %s, speaker %s, output %s.\n",
48            controlVal.gate ? "on" : "off",
49            controlVal.speaker ? "on" : "off",
50            controlVal.timer ? "on" : "off");
51    pkt->setLE((uint8_t)controlVal);
52    pkt->makeAtomicResponse();
53    return latency;
54}
55
56Tick
57X86ISA::Speaker::write(PacketPtr pkt)
58{
59    assert(pkt->getAddr() == pioAddr);
60    assert(pkt->getSize() == 1);
61    SpeakerControl val = pkt->getLE<uint8_t>();
62    controlVal.gate = val.gate;
63    //Change the gate value in the timer.
64    if (!val.gate)
65        warn("The gate bit of the pc speaker isn't implemented and "
66                "is always on.\n");
67    //This would control whether the timer output is hooked up to a physical
68    //speaker. Since M5 can't make noise, it's value doesn't actually do
69    //anything.
70    controlVal.speaker = val.speaker;
71    DPRINTF(PcSpeaker, "Writing to speaker device: gate %s, speaker %s.\n",
72            controlVal.gate ? "on" : "off", controlVal.speaker ? "on" : "off");
73    pkt->makeAtomicResponse();
74    return latency;
75}
76
77void
78X86ISA::Speaker::serialize(CheckpointOut &cp) const
79{
80    SERIALIZE_SCALAR(controlVal);
81}
82
83void
84X86ISA::Speaker::unserialize(CheckpointIn &cp)
85{
86    UNSERIALIZE_SCALAR(controlVal);
87}
88
89X86ISA::Speaker *
90PcSpeakerParams::create()
91{
92    return new X86ISA::Speaker(this);
93}
94