📄 io.h
字号:
//// Copyright (c) 2004 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card, but now handles other// hardware as well. These files contain a (mostly) user-space driver // for the Unichrome board found on Via's EPIA motherboards.//// The information for implementing this driver has been gathered// from the following sources://// - The DirectFB Unichrome driver// Copyright (c) 2003 Andreas Robinson, All rights reserved.//// - Andreas Robinson's MPEG-2 decoder for the Unichrome board.// Copyright (c) 2003 Andreas Robinson, All rights reserved.//// - Via's Unichrome Framebuffer driver// Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.// Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#ifndef DXR3PLAYER_UNICHROME_IO_H#define DXR3PLAYER_UNICHROME_IO_H//------------------------------------------------------------------------------#include "I2C.h"//------------------------------------------------------------------------------namespace unichrome {//------------------------------------------------------------------------------#include <cstdlib>#include <inttypes.h>#include <sys/io.h>//------------------------------------------------------------------------------/** * Class to handle low-level I/O with the Unichrome board. */class IO{public: /** * A simple, non-indexed port. */ class Port { protected: /** * The port number. */ size_t portNumber; public: /** * Construct the port object. */ Port(size_t portNumber); /** * Read a byte from the port. */ uint8_t read8(); /** * Write a byte to the port. */ void write8(uint8_t x); }; /** * An indexed port */ class IndexedPort : public Port { public: /** * Construct the indexed port with the given base port number. */ IndexedPort(size_t basePort); /** * Read a byte from the given index. */ unsigned read(unsigned index); /** * Write a byte to the given index. */ void write(unsigned index, unsigned data); /** * Write a masked byte to the given index */ void writeMasked(unsigned index, unsigned data, unsigned mask); }; /** * The attribute port. */ class AttributePort : public Port { public: /** * Construct the indexed port with the given base port number. */ AttributePort(size_t basePort); /** * Read a byte from the given index. */ unsigned read(unsigned index); /** * Write a byte to the given index. */ void write(unsigned index, unsigned data); }; friend class AttributePort;private: /** * Broken up register */ class BrokenUpRegister { protected: void doWrite(IndexedPort& /*port*/, const unsigned /*data*/) {} public: virtual void write(IndexedPort& port, const unsigned data) = 0; };public: /** * A register part. */ template <unsigned index, unsigned firstBit, unsigned lastBit, class Super = BrokenUpRegister> class RegisterPart : public Super { protected: void doWrite(IndexedPort& port, const unsigned data); public: virtual void write(IndexedPort& port, const unsigned data); }; private: /** * The vendor ID for the device. */ static const unsigned VENDOR_ID = 0x1106; /** * The device ID for the device. */ static const unsigned DEVICE_ID = 0x3122; /** * Base address index: framebuffer. */ static const size_t BASEIDX_FRAMEBUFFER = 0; /** * Base address index: mmio */ static const size_t BASEIDX_MMIO = 1;public: /** * The framebuffer size */ static const size_t FRAMEBUFFER_SIZE = 32*1024*1024; /** * The VGA sequencer index register port */ static const size_t PORT_SEQUENCER = 0x3c4; /** * The control index register port */ static const size_t PORT_CONTROL = 0x3d4; /** * The graphics index register port */ static const size_t PORT_GRAPHICS = 0x3ce; /** * The status register port */ static const size_t PORT_STATUS = 0x3da; /** * The attribute register port */ static const size_t PORT_ATTRIBUTE = 0x3c0; /** * The miscellanous output port */ static const size_t PORT_MISC_OUTPUT = 0x3c2; /** * The miscellanous output port2 */ static const size_t PORT_MISC_OUTPUT2 = 0x3c3; /** * The miscellanous input port */ static const size_t PORT_MISC_INPUT = 0x3cc;private: /** * The mapped address of the framebuffer area */ void* framebuffer; /** * The mapped address of the MMIO area */ void* mmio; /** * The size of the MMIO area. */ size_t mmioSize; /** * The revision of the device found. */ unsigned revision;public: /** * The VGA sequencer port. */ IndexedPort sequencer; /** * The control port. */ IndexedPort control; /** * The graphics port. */ IndexedPort graphics; /** * The status port. */ Port status; /** * The attribute port. */ AttributePort attribute; /** * The miscellanous output port. */ Port miscOutput; /** * The miscellanous output port 2. */ Port miscOutput2; /** * The miscellanous input port. */ Port miscInput; /** * The I2C interface. */ I2C i2c; /** * Construct the low-level I/O subsystem */ IO(); /** * Destroy the low-level I/O subsystem. */ ~IO(); /** * Function to access a 32-bit memory-mapped I/O register. */ volatile uint32_t& reg(size_t registerNumber); /** * Get the address of the mapped frame buffer. */ volatile unsigned char* getFrameBuffer(); /** * Get the revision of the device. */ unsigned getRevision() const;};//------------------------------------------------------------------------------// Inline definitions//------------------------------------------------------------------------------inline IO::Port::Port(size_t portNumber) : portNumber(portNumber){}inline uint8_t IO::Port::read8(){ return inb(portNumber);}inline void IO::Port::write8(uint8_t x){ outb(x, portNumber);}//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline IO::IndexedPort::IndexedPort(size_t basePort) : Port(basePort){}//------------------------------------------------------------------------------inline unsigned IO::IndexedPort::read(unsigned index){ outb(index, portNumber); return inb(portNumber+1);}//------------------------------------------------------------------------------inline void IO::IndexedPort::write(unsigned index, unsigned data){ outb(index, portNumber); outb(data, portNumber+1);}//------------------------------------------------------------------------------inline void IO::IndexedPort::writeMasked(unsigned index, unsigned data, unsigned mask){ outb(index, portNumber); unsigned x = inb(portNumber + 1); x &= ~mask; x |= data&mask; outb(x, portNumber + 1);}//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline IO::AttributePort::AttributePort(size_t basePort) : Port(basePort){} //------------------------------------------------------------------------------inline unsigned IO::AttributePort::read(unsigned index){ inb(PORT_STATUS); outb(index, portNumber); return inb(portNumber+1);} //------------------------------------------------------------------------------inline void IO::AttributePort::write(unsigned index, unsigned data){ inb(PORT_STATUS); outb(index, portNumber); outb(data, portNumber);}//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline volatile uint32_t& IO::reg(size_t registerNumber){ return reinterpret_cast<volatile uint32_t*>(mmio)[registerNumber/4];}//------------------------------------------------------------------------------inline volatile unsigned char* IO::getFrameBuffer(){ return reinterpret_cast<unsigned char*>(framebuffer);}//------------------------------------------------------------------------------inline unsigned IO::getRevision() const{ return revision;}//------------------------------------------------------------------------------// Template definitions//------------------------------------------------------------------------------template <unsigned index, unsigned firstBit, unsigned lastBit, class Super>void IO::RegisterPart<index, firstBit, lastBit, Super>::doWrite(IndexedPort& port, const unsigned data){ size_t numBits = lastBit + 1 - firstBit; size_t mask = ~0; mask <<= numBits; mask = ~mask; size_t currentData = data&mask; currentData <<= firstBit; mask <<= firstBit; port.writeMasked(index, currentData, mask); Super::doWrite(port, data>>numBits);}//------------------------------------------------------------------------------template <unsigned index, unsigned firstBit, unsigned lastBit, class Super>void IO::RegisterPart<index, firstBit, lastBit, Super>::write(IndexedPort& port, const unsigned data){ doWrite(port, data);}//------------------------------------------------------------------------------} /* namespace unichrome *///------------------------------------------------------------------------------#endif // DXR3PLAYER_UNICHROME_IO_H// Local variables:// mode: c++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -