15390SN/A/*
25445SN/A * Copyright (c) 2008 The Regents of The University of Michigan
35390SN/A * All rights reserved.
45390SN/A *
55390SN/A * Redistribution and use in source and binary forms, with or without
65390SN/A * modification, are permitted provided that the following conditions are
75390SN/A * met: redistributions of source code must retain the above copyright
85390SN/A * notice, this list of conditions and the following disclaimer;
95390SN/A * redistributions in binary form must reproduce the above copyright
105390SN/A * notice, this list of conditions and the following disclaimer in the
115390SN/A * documentation and/or other materials provided with the distribution;
125390SN/A * neither the name of the copyright holders nor the names of its
135390SN/A * contributors may be used to endorse or promote products derived from
145390SN/A * this software without specific prior written permission.
155390SN/A *
165390SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175390SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185390SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195390SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205390SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215390SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225390SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235390SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245390SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255390SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265390SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275390SN/A *
285390SN/A * Authors: Gabe Black
295390SN/A */
305390SN/A
3111793Sbrandon.potter@amd.com#include "dev/x86/speaker.hh"
3211793Sbrandon.potter@amd.com
335390SN/A#include "base/bitunion.hh"
345445SN/A#include "base/trace.hh"
358232Snate@binkert.org#include "debug/PcSpeaker.hh"
365636Sgblack@eecs.umich.edu#include "dev/x86/i8254.hh"
375636Sgblack@eecs.umich.edu#include "mem/packet.hh"
385390SN/A#include "mem/packet_access.hh"
395390SN/A
405390SN/ATick
415390SN/AX86ISA::Speaker::read(PacketPtr pkt)
425390SN/A{
435636Sgblack@eecs.umich.edu    assert(pkt->getAddr() == pioAddr);
445390SN/A    assert(pkt->getSize() == 1);
455636Sgblack@eecs.umich.edu    controlVal.timer = timer->outputHigh(2) ? 1 : 0;
465636Sgblack@eecs.umich.edu    DPRINTF(PcSpeaker,
475445SN/A            "Reading from speaker device: gate %s, speaker %s, output %s.\n",
485445SN/A            controlVal.gate ? "on" : "off",
495445SN/A            controlVal.speaker ? "on" : "off",
505445SN/A            controlVal.timer ? "on" : "off");
5113229Sgabeblack@google.com    pkt->setLE((uint8_t)controlVal);
525898Sgblack@eecs.umich.edu    pkt->makeAtomicResponse();
535390SN/A    return latency;
545390SN/A}
555390SN/A
565390SN/ATick
575390SN/AX86ISA::Speaker::write(PacketPtr pkt)
585390SN/A{
595636Sgblack@eecs.umich.edu    assert(pkt->getAddr() == pioAddr);
605390SN/A    assert(pkt->getSize() == 1);
6113229Sgabeblack@google.com    SpeakerControl val = pkt->getLE<uint8_t>();
625445SN/A    controlVal.gate = val.gate;
635445SN/A    //Change the gate value in the timer.
645445SN/A    if (!val.gate)
655445SN/A        warn("The gate bit of the pc speaker isn't implemented and "
665445SN/A                "is always on.\n");
675445SN/A    //This would control whether the timer output is hooked up to a physical
685445SN/A    //speaker. Since M5 can't make noise, it's value doesn't actually do
695445SN/A    //anything.
705445SN/A    controlVal.speaker = val.speaker;
715636Sgblack@eecs.umich.edu    DPRINTF(PcSpeaker, "Writing to speaker device: gate %s, speaker %s.\n",
725445SN/A            controlVal.gate ? "on" : "off", controlVal.speaker ? "on" : "off");
735898Sgblack@eecs.umich.edu    pkt->makeAtomicResponse();
745390SN/A    return latency;
755390SN/A}
765636Sgblack@eecs.umich.edu
777903Shestness@cs.utexas.eduvoid
7810905Sandreas.sandberg@arm.comX86ISA::Speaker::serialize(CheckpointOut &cp) const
797903Shestness@cs.utexas.edu{
8012450Sgabeblack@google.com    SERIALIZE_SCALAR(controlVal);
817903Shestness@cs.utexas.edu}
827903Shestness@cs.utexas.edu
837903Shestness@cs.utexas.eduvoid
8410905Sandreas.sandberg@arm.comX86ISA::Speaker::unserialize(CheckpointIn &cp)
857903Shestness@cs.utexas.edu{
8612450Sgabeblack@google.com    UNSERIALIZE_SCALAR(controlVal);
877903Shestness@cs.utexas.edu}
887903Shestness@cs.utexas.edu
895636Sgblack@eecs.umich.eduX86ISA::Speaker *
905636Sgblack@eecs.umich.eduPcSpeakerParams::create()
915636Sgblack@eecs.umich.edu{
925636Sgblack@eecs.umich.edu    return new X86ISA::Speaker(this);
935636Sgblack@eecs.umich.edu}
94