speaker.cc revision 12450
1955SN/A/*
2955SN/A * Copyright (c) 2008 The Regents of The University of Michigan
31762SN/A * All rights reserved.
4955SN/A *
5955SN/A * Redistribution and use in source and binary forms, with or without
6955SN/A * modification, are permitted provided that the following conditions are
7955SN/A * met: redistributions of source code must retain the above copyright
8955SN/A * notice, this list of conditions and the following disclaimer;
9955SN/A * redistributions in binary form must reproduce the above copyright
10955SN/A * notice, this list of conditions and the following disclaimer in the
11955SN/A * documentation and/or other materials provided with the distribution;
12955SN/A * neither the name of the copyright holders nor the names of its
13955SN/A * contributors may be used to endorse or promote products derived from
14955SN/A * this software without specific prior written permission.
15955SN/A *
16955SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17955SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18955SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19955SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20955SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21955SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22955SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23955SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24955SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25955SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26955SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27955SN/A *
282665Ssaidi@eecs.umich.edu * Authors: Gabe Black
294762Snate@binkert.org */
30955SN/A
315522Snate@binkert.org#include "dev/x86/speaker.hh"
326143Snate@binkert.org
334762Snate@binkert.org#include "base/bitunion.hh"
345522Snate@binkert.org#include "base/trace.hh"
35955SN/A#include "debug/PcSpeaker.hh"
365522Snate@binkert.org#include "dev/x86/i8254.hh"
37955SN/A#include "mem/packet.hh"
385522Snate@binkert.org#include "mem/packet_access.hh"
394202Sbinkertn@umich.edu
405742Snate@binkert.orgTick
41955SN/AX86ISA::Speaker::read(PacketPtr pkt)
424381Sbinkertn@umich.edu{
434381Sbinkertn@umich.edu    assert(pkt->getAddr() == pioAddr);
448334Snate@binkert.org    assert(pkt->getSize() == 1);
45955SN/A    controlVal.timer = timer->outputHigh(2) ? 1 : 0;
46955SN/A    DPRINTF(PcSpeaker,
474202Sbinkertn@umich.edu            "Reading from speaker device: gate %s, speaker %s, output %s.\n",
48955SN/A            controlVal.gate ? "on" : "off",
494382Sbinkertn@umich.edu            controlVal.speaker ? "on" : "off",
504382Sbinkertn@umich.edu            controlVal.timer ? "on" : "off");
514382Sbinkertn@umich.edu    pkt->set((uint8_t)controlVal);
526654Snate@binkert.org    pkt->makeAtomicResponse();
535517Snate@binkert.org    return latency;
548614Sgblack@eecs.umich.edu}
557674Snate@binkert.org
566143Snate@binkert.orgTick
576143Snate@binkert.orgX86ISA::Speaker::write(PacketPtr pkt)
586143Snate@binkert.org{
598233Snate@binkert.org    assert(pkt->getAddr() == pioAddr);
608233Snate@binkert.org    assert(pkt->getSize() == 1);
618233Snate@binkert.org    SpeakerControl val = pkt->get<uint8_t>();
628233Snate@binkert.org    controlVal.gate = val.gate;
638233Snate@binkert.org    //Change the gate value in the timer.
648334Snate@binkert.org    if (!val.gate)
658334Snate@binkert.org        warn("The gate bit of the pc speaker isn't implemented and "
668233Snate@binkert.org                "is always on.\n");
678233Snate@binkert.org    //This would control whether the timer output is hooked up to a physical
688233Snate@binkert.org    //speaker. Since M5 can't make noise, it's value doesn't actually do
698233Snate@binkert.org    //anything.
708233Snate@binkert.org    controlVal.speaker = val.speaker;
718233Snate@binkert.org    DPRINTF(PcSpeaker, "Writing to speaker device: gate %s, speaker %s.\n",
726143Snate@binkert.org            controlVal.gate ? "on" : "off", controlVal.speaker ? "on" : "off");
738233Snate@binkert.org    pkt->makeAtomicResponse();
748233Snate@binkert.org    return latency;
758233Snate@binkert.org}
766143Snate@binkert.org
776143Snate@binkert.orgvoid
786143Snate@binkert.orgX86ISA::Speaker::serialize(CheckpointOut &cp) const
796143Snate@binkert.org{
808233Snate@binkert.org    SERIALIZE_SCALAR(controlVal);
818233Snate@binkert.org}
828233Snate@binkert.org
836143Snate@binkert.orgvoid
848233Snate@binkert.orgX86ISA::Speaker::unserialize(CheckpointIn &cp)
858233Snate@binkert.org{
868233Snate@binkert.org    UNSERIALIZE_SCALAR(controlVal);
878233Snate@binkert.org}
886143Snate@binkert.org
896143Snate@binkert.orgX86ISA::Speaker *
906143Snate@binkert.orgPcSpeakerParams::create()
914762Snate@binkert.org{
926143Snate@binkert.org    return new X86ISA::Speaker(this);
938233Snate@binkert.org}
948233Snate@binkert.org