speaker.cc revision 13229
12810SN/A/* 211375Sandreas.hansson@arm.com * Copyright (c) 2008 The Regents of The University of Michigan 39347SAndreas.Sandberg@arm.com * All rights reserved. 49347SAndreas.Sandberg@arm.com * 59347SAndreas.Sandberg@arm.com * Redistribution and use in source and binary forms, with or without 69347SAndreas.Sandberg@arm.com * modification, are permitted provided that the following conditions are 79347SAndreas.Sandberg@arm.com * met: redistributions of source code must retain the above copyright 89347SAndreas.Sandberg@arm.com * notice, this list of conditions and the following disclaimer; 99347SAndreas.Sandberg@arm.com * redistributions in binary form must reproduce the above copyright 109347SAndreas.Sandberg@arm.com * notice, this list of conditions and the following disclaimer in the 119347SAndreas.Sandberg@arm.com * documentation and/or other materials provided with the distribution; 129347SAndreas.Sandberg@arm.com * neither the name of the copyright holders nor the names of its 139347SAndreas.Sandberg@arm.com * contributors may be used to endorse or promote products derived from 142810SN/A * this software without specific prior written permission. 152810SN/A * 162810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272810SN/A * 282810SN/A * Authors: Gabe Black 292810SN/A */ 302810SN/A 312810SN/A#include "dev/x86/speaker.hh" 322810SN/A 332810SN/A#include "base/bitunion.hh" 342810SN/A#include "base/trace.hh" 352810SN/A#include "debug/PcSpeaker.hh" 362810SN/A#include "dev/x86/i8254.hh" 372810SN/A#include "mem/packet.hh" 382810SN/A#include "mem/packet_access.hh" 392810SN/A 402810SN/ATick 419347SAndreas.Sandberg@arm.comX86ISA::Speaker::read(PacketPtr pkt) 422810SN/A{ 432810SN/A assert(pkt->getAddr() == pioAddr); 442810SN/A assert(pkt->getSize() == 1); 454626SN/A controlVal.timer = timer->outputHigh(2) ? 1 : 0; 462810SN/A DPRINTF(PcSpeaker, 472810SN/A "Reading from speaker device: gate %s, speaker %s, output %s.\n", 485338Sstever@gmail.com controlVal.gate ? "on" : "off", 492810SN/A controlVal.speaker ? "on" : "off", 5012727Snikos.nikoleris@arm.com controlVal.timer ? "on" : "off"); 5112727Snikos.nikoleris@arm.com pkt->setLE((uint8_t)controlVal); 5212727Snikos.nikoleris@arm.com pkt->makeAtomicResponse(); 5312727Snikos.nikoleris@arm.com return latency; 545314SN/A} 5511375Sandreas.hansson@arm.com 5611375Sandreas.hansson@arm.comTick 5711375Sandreas.hansson@arm.comX86ISA::Speaker::write(PacketPtr pkt) 5811375Sandreas.hansson@arm.com{ 594666SN/A assert(pkt->getAddr() == pioAddr); 604626SN/A assert(pkt->getSize() == 1); 6110764Sandreas.hansson@arm.com SpeakerControl val = pkt->getLE<uint8_t>(); 6211197Sandreas.hansson@arm.com controlVal.gate = val.gate; 632810SN/A //Change the gate value in the timer. 643149SN/A if (!val.gate) 652810SN/A warn("The gate bit of the pc speaker isn't implemented and " 662810SN/A "is always on.\n"); 672810SN/A //This would control whether the timer output is hooked up to a physical 682810SN/A //speaker. Since M5 can't make noise, it's value doesn't actually do 6911197Sandreas.hansson@arm.com //anything. 702810SN/A controlVal.speaker = val.speaker; 714666SN/A DPRINTF(PcSpeaker, "Writing to speaker device: gate %s, speaker %s.\n", 722810SN/A controlVal.gate ? "on" : "off", controlVal.speaker ? "on" : "off"); 732810SN/A pkt->makeAtomicResponse(); 742810SN/A return latency; 752810SN/A} 762810SN/A 772810SN/Avoid 782810SN/AX86ISA::Speaker::serialize(CheckpointOut &cp) const 792810SN/A{ 802810SN/A SERIALIZE_SCALAR(controlVal); 812810SN/A} 824666SN/A 834666SN/Avoid 842810SN/AX86ISA::Speaker::unserialize(CheckpointIn &cp) 852810SN/A{ 862810SN/A UNSERIALIZE_SCALAR(controlVal); 872810SN/A} 8811284Sandreas.hansson@arm.com 892810SN/AX86ISA::Speaker * 9011375Sandreas.hansson@arm.comPcSpeakerParams::create() 9111375Sandreas.hansson@arm.com{ 9211375Sandreas.hansson@arm.com return new X86ISA::Speaker(this); 932810SN/A} 942810SN/A