speaker.cc revision 8232
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 315390SN/A#include "base/bitunion.hh" 325445SN/A#include "base/trace.hh" 338232Snate@binkert.org#include "debug/PcSpeaker.hh" 345636Sgblack@eecs.umich.edu#include "dev/x86/i8254.hh" 355636Sgblack@eecs.umich.edu#include "dev/x86/speaker.hh" 365636Sgblack@eecs.umich.edu#include "mem/packet.hh" 375390SN/A#include "mem/packet_access.hh" 385390SN/A 395390SN/ATick 405390SN/AX86ISA::Speaker::read(PacketPtr pkt) 415390SN/A{ 425636Sgblack@eecs.umich.edu assert(pkt->getAddr() == pioAddr); 435390SN/A assert(pkt->getSize() == 1); 445636Sgblack@eecs.umich.edu controlVal.timer = timer->outputHigh(2) ? 1 : 0; 455636Sgblack@eecs.umich.edu DPRINTF(PcSpeaker, 465445SN/A "Reading from speaker device: gate %s, speaker %s, output %s.\n", 475445SN/A controlVal.gate ? "on" : "off", 485445SN/A controlVal.speaker ? "on" : "off", 495445SN/A controlVal.timer ? "on" : "off"); 505445SN/A pkt->set((uint8_t)controlVal); 515898Sgblack@eecs.umich.edu pkt->makeAtomicResponse(); 525390SN/A return latency; 535390SN/A} 545390SN/A 555390SN/ATick 565390SN/AX86ISA::Speaker::write(PacketPtr pkt) 575390SN/A{ 585636Sgblack@eecs.umich.edu assert(pkt->getAddr() == pioAddr); 595390SN/A assert(pkt->getSize() == 1); 605390SN/A SpeakerControl val = pkt->get<uint8_t>(); 615445SN/A controlVal.gate = val.gate; 625445SN/A //Change the gate value in the timer. 635445SN/A if (!val.gate) 645445SN/A warn("The gate bit of the pc speaker isn't implemented and " 655445SN/A "is always on.\n"); 665445SN/A //This would control whether the timer output is hooked up to a physical 675445SN/A //speaker. Since M5 can't make noise, it's value doesn't actually do 685445SN/A //anything. 695445SN/A controlVal.speaker = val.speaker; 705636Sgblack@eecs.umich.edu DPRINTF(PcSpeaker, "Writing to speaker device: gate %s, speaker %s.\n", 715445SN/A controlVal.gate ? "on" : "off", controlVal.speaker ? "on" : "off"); 725898Sgblack@eecs.umich.edu pkt->makeAtomicResponse(); 735390SN/A return latency; 745390SN/A} 755636Sgblack@eecs.umich.edu 767903Shestness@cs.utexas.eduvoid 777903Shestness@cs.utexas.eduX86ISA::Speaker::serialize(std::ostream &os) 787903Shestness@cs.utexas.edu{ 797903Shestness@cs.utexas.edu uint8_t controlValData = controlVal.__data; 807903Shestness@cs.utexas.edu SERIALIZE_SCALAR(controlValData); 817903Shestness@cs.utexas.edu} 827903Shestness@cs.utexas.edu 837903Shestness@cs.utexas.eduvoid 847903Shestness@cs.utexas.eduX86ISA::Speaker::unserialize(Checkpoint *cp, const std::string §ion) 857903Shestness@cs.utexas.edu{ 867903Shestness@cs.utexas.edu uint8_t controlValData; 877903Shestness@cs.utexas.edu UNSERIALIZE_SCALAR(controlValData); 887903Shestness@cs.utexas.edu controlVal.__data = controlValData; 897903Shestness@cs.utexas.edu} 907903Shestness@cs.utexas.edu 915636Sgblack@eecs.umich.eduX86ISA::Speaker * 925636Sgblack@eecs.umich.eduPcSpeakerParams::create() 935636Sgblack@eecs.umich.edu{ 945636Sgblack@eecs.umich.edu return new X86ISA::Speaker(this); 955636Sgblack@eecs.umich.edu} 96