speaker.cc revision 5898
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" 335636Sgblack@eecs.umich.edu#include "dev/x86/i8254.hh" 345636Sgblack@eecs.umich.edu#include "dev/x86/speaker.hh" 355636Sgblack@eecs.umich.edu#include "mem/packet.hh" 365390SN/A#include "mem/packet_access.hh" 375390SN/A 385390SN/ATick 395390SN/AX86ISA::Speaker::read(PacketPtr pkt) 405390SN/A{ 415636Sgblack@eecs.umich.edu assert(pkt->getAddr() == pioAddr); 425390SN/A assert(pkt->getSize() == 1); 435636Sgblack@eecs.umich.edu controlVal.timer = timer->outputHigh(2) ? 1 : 0; 445636Sgblack@eecs.umich.edu DPRINTF(PcSpeaker, 455445SN/A "Reading from speaker device: gate %s, speaker %s, output %s.\n", 465445SN/A controlVal.gate ? "on" : "off", 475445SN/A controlVal.speaker ? "on" : "off", 485445SN/A controlVal.timer ? "on" : "off"); 495445SN/A pkt->set((uint8_t)controlVal); 505898Sgblack@eecs.umich.edu pkt->makeAtomicResponse(); 515390SN/A return latency; 525390SN/A} 535390SN/A 545390SN/ATick 555390SN/AX86ISA::Speaker::write(PacketPtr pkt) 565390SN/A{ 575636Sgblack@eecs.umich.edu assert(pkt->getAddr() == pioAddr); 585390SN/A assert(pkt->getSize() == 1); 595390SN/A SpeakerControl val = pkt->get<uint8_t>(); 605445SN/A controlVal.gate = val.gate; 615445SN/A //Change the gate value in the timer. 625445SN/A if (!val.gate) 635445SN/A warn("The gate bit of the pc speaker isn't implemented and " 645445SN/A "is always on.\n"); 655445SN/A //This would control whether the timer output is hooked up to a physical 665445SN/A //speaker. Since M5 can't make noise, it's value doesn't actually do 675445SN/A //anything. 685445SN/A controlVal.speaker = val.speaker; 695636Sgblack@eecs.umich.edu DPRINTF(PcSpeaker, "Writing to speaker device: gate %s, speaker %s.\n", 705445SN/A controlVal.gate ? "on" : "off", controlVal.speaker ? "on" : "off"); 715898Sgblack@eecs.umich.edu pkt->makeAtomicResponse(); 725390SN/A return latency; 735390SN/A} 745636Sgblack@eecs.umich.edu 755636Sgblack@eecs.umich.eduX86ISA::Speaker * 765636Sgblack@eecs.umich.eduPcSpeakerParams::create() 775636Sgblack@eecs.umich.edu{ 785636Sgblack@eecs.umich.edu return new X86ISA::Speaker(this); 795636Sgblack@eecs.umich.edu} 80