2020-04-13 23:04:37 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2023-04-01 17:05:34 +00:00
|
|
|
Copyright (C) 2018-23 divingkatae and maximum
|
2020-04-13 23:04:37 +00:00
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
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 3 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, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-03-31 16:25:58 +00:00
|
|
|
#ifndef ATI_RAGE_H
|
|
|
|
#define ATI_RAGE_H
|
|
|
|
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <devices/common/pci/pcidevice.h>
|
2022-04-13 21:06:42 +00:00
|
|
|
#include <devices/video/atimach64defs.h>
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <devices/video/displayid.h>
|
2021-11-09 12:40:13 +00:00
|
|
|
#include <devices/video/videoctrl.h>
|
2021-10-23 18:17:47 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <cinttypes>
|
2021-11-17 22:30:43 +00:00
|
|
|
#include <memory>
|
2020-03-27 17:54:25 +00:00
|
|
|
|
2021-02-08 01:20:32 +00:00
|
|
|
/* Mach64 PLL register indices. */
|
|
|
|
enum {
|
|
|
|
PLL_REF_DIV = 2, // reference divider, same for all Mach64 clocks
|
|
|
|
PLL_VCLK_CNTL = 5,
|
|
|
|
VCLK_POST_DIV = 6,
|
|
|
|
VCLK0_FB_DIV = 7, // feedback divider for VCLK0
|
|
|
|
VCLK1_FB_DIV = 8, // feedback divider for VCLK1
|
|
|
|
VCLK2_FB_DIV = 9, // feedback divider for VCLK2
|
|
|
|
VCLK3_FB_DIV = 10, // feedback divider for VCLK3
|
|
|
|
PLL_EXT_CNTL = 11,
|
|
|
|
};
|
|
|
|
|
2021-11-09 12:40:13 +00:00
|
|
|
class ATIRage : public PCIDevice, public VideoCtrlBase {
|
2020-03-27 17:54:25 +00:00
|
|
|
public:
|
2022-07-18 09:48:23 +00:00
|
|
|
ATIRage(uint16_t dev_id);
|
2021-11-17 22:30:43 +00:00
|
|
|
~ATIRage() = default;
|
2020-03-27 17:54:25 +00:00
|
|
|
|
2022-07-18 09:48:23 +00:00
|
|
|
static std::unique_ptr<HWComponent> create_gt() {
|
|
|
|
return std::unique_ptr<ATIRage>(new ATIRage(ATI_RAGE_GT_DEV_ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::unique_ptr<HWComponent> create_pro() {
|
|
|
|
return std::unique_ptr<ATIRage>(new ATIRage(ATI_RAGE_PRO_DEV_ID));
|
|
|
|
}
|
|
|
|
|
2023-04-01 17:05:34 +00:00
|
|
|
// MMIODevice methods
|
2022-08-22 10:16:31 +00:00
|
|
|
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
|
|
|
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
2020-03-31 16:25:58 +00:00
|
|
|
|
2023-04-01 17:05:34 +00:00
|
|
|
// PCI device methods
|
Fix PCI config r/w of byte and word and unaligned.
dingusppc could not read bytes from offset 1,2,3 or words from offset 2.
dingusppc did not read words from offset 1,3 and longs from offset 1,2,3 in the same way as a real Power Mac 8600 or B&W G3.
This commit fixes those issues.
- Added pci_cfg_rev_read. It takes a 32 bit value from offset 0 and returns a value of the specified size using bytes starting from the specified offset. Offsets 4,5, & 6 wrap around to 0,1, & 2 respectively. The result bytes are in flipped order as required by the read method (so a value of 0x12345678 is returned as 0x78563412)
A real Power Mac 8600 might return a random byte for offset 4, 5, 6 for vci0 but usually not for pci1. A B&W G3 seems to always wrap around correctly. We won't read random bytes, and we won't read a default such as 00 or FF. We'll do the wrap around which makes the most sense because writing 0x12345678 to any offset and reading from the same offset should produce the value that was written.
- Added pci_cfg_rev_write. It takes a 32 bit value from offset 0, and modifies a specified number of bytes starting at a specified offset with the offset wrapping around to 0 if it exceeds 3. The modified bytes take their new values from the flipped bytes passed to pci_cfg_write. When size is 4, the original value is not used since all bytes will be modified.
Basically, those two functions handle all the sizes and all the offsets and replace calls to BYTESWAP_32, read_mem or read_mem_rev, and write_mem or write_mem_rev.
read_mem_rev, as it was used by pcidevice and some other places, could read beyond offset 3 if it were ever passed a reg_offs value that did not have offset as 0. Since the offset was always zero, it would always read the wrong byte or word if they were not at offset 0. Same for read_mem as used by mpc106.
write_mem_rev, as it was used by pcidevice and some other places, could write beyond offset 3 if it were ever passed a reg_offs value that did not have offset as 0. Since the offset was always zero, it would always write the wrong byte or word if they were not at offset 0. Same for write_mem as used by mpc106.
pcidevice:
- The logging macros should be used to handle all config register access logging.
- Unaligned PCI config register accesses will be output as ERROR instead of WARNING.
- The logging macros include the offset and size. They also include the value for named registers or for writes.
- Added MMIODevice read and write methods so that PCIDevice is not abstract if a PCIDevice doesn't override the read and write method since some PCIDevices don't have MMIO.
pcihost:
- Added pci_find_device stub for handling PCI bridges in future commit.
bandit and mpc106:
- PCI host controllers will handle all PCI config access alignment and sizing. A PCIDevice will always access config registers as 32 bits on a 4 byte boundary. The AccessDetails passed to a PCIDevice config read or write method is there only for logging purposes.
bandit:
- Common MMIO code is moved to new BanditHost class so both Bandit and Chaos can use it. PCI related code is moved to new BanditPCI class.
- Simplify IDSEL to/from PCI device number conversion by removing the shift or subtract.
- Remove BANDIT_ID_SEL check. The IDSEL conversion to PCI device number can find the bandit PCI device.
- For logging, make best guess of PCI device number from invalid IDSEL - the result is always reasonable for device 0x00 to 0x0A when accessing config register 0x00 (as one would do when scanning for PCI devices like lspci does).
mpc106:
- Common config space code is put in cfg_setup. It handles extracting the offset.
- Added code to log access to unimplemented config registers of grackle.
- Don't call setup_ram when writing to config registers that setup_ram doesn't use.
- pci_cfg_read calls READ_DWORD_LE_A and pci_cfg_write calls WRITE_DWORD_LE_A. When reading or writing memory that is organized as little endian dwords, such as my_pci_cfg_hdr of mpc106, the function should explicitly state that it's little endian so that the emulator may be ported one day to a CPU architecture that is not little endian.
atirage:
- The changes correctly place user_cfg at byte 0x40 instead of 0x43 and writes the correct byte depending on size and offset.
2022-09-02 10:32:28 +00:00
|
|
|
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
|
|
|
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
2020-03-27 17:54:25 +00:00
|
|
|
|
2023-04-01 17:05:34 +00:00
|
|
|
// I/O space access methods
|
2020-05-12 18:55:45 +00:00
|
|
|
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res);
|
|
|
|
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
|
2020-03-31 19:19:10 +00:00
|
|
|
|
|
|
|
protected:
|
2022-03-13 19:58:31 +00:00
|
|
|
void notify_bar_change(int bar_num);
|
2020-04-13 23:04:37 +00:00
|
|
|
const char* get_reg_name(uint32_t reg_offset);
|
2022-03-13 19:58:31 +00:00
|
|
|
bool io_access_allowed(uint32_t offset);
|
2023-04-01 17:05:34 +00:00
|
|
|
uint32_t read_reg(uint32_t reg_offset, uint32_t size);
|
|
|
|
void write_reg(uint32_t reg_addr, uint32_t value, uint32_t size);
|
2021-02-08 01:20:32 +00:00
|
|
|
float calc_pll_freq(int scale, int fb_div);
|
|
|
|
void verbose_pixel_format(int crtc_index);
|
2023-04-01 17:05:34 +00:00
|
|
|
void crtc_update();
|
2021-02-08 01:20:32 +00:00
|
|
|
void crtc_enable();
|
2021-09-11 19:02:46 +00:00
|
|
|
void draw_hw_cursor(uint8_t *dst_buf, int dst_pitch);
|
2023-04-01 23:56:24 +00:00
|
|
|
void get_cursor_position(int& x, int& y);
|
2020-03-31 19:19:10 +00:00
|
|
|
|
2020-03-27 17:54:25 +00:00
|
|
|
private:
|
2023-04-01 17:05:34 +00:00
|
|
|
uint32_t regs[512] = {}; // internal registers
|
|
|
|
uint8_t plls[64] = {}; // internal PLL registers
|
2020-03-27 17:54:25 +00:00
|
|
|
|
2023-10-09 17:18:55 +00:00
|
|
|
uint8_t cmd_fifo_size = 0;
|
|
|
|
|
2023-04-01 17:05:34 +00:00
|
|
|
// Video RAM variables
|
2021-11-17 22:30:43 +00:00
|
|
|
std::unique_ptr<uint8_t[]> vram_ptr;
|
2020-05-28 21:47:20 +00:00
|
|
|
uint32_t vram_size;
|
2020-05-28 20:36:55 +00:00
|
|
|
|
2022-03-13 19:58:31 +00:00
|
|
|
uint32_t aperture_base = 0;
|
|
|
|
uint32_t io_base = 0;
|
|
|
|
uint8_t user_cfg = 8;
|
2020-05-28 21:47:20 +00:00
|
|
|
|
2021-11-17 22:30:43 +00:00
|
|
|
std::unique_ptr<DisplayID> disp_id;
|
2020-06-10 23:30:10 +00:00
|
|
|
|
2023-04-01 10:08:25 +00:00
|
|
|
// DAC interface state
|
|
|
|
uint8_t dac_wr_index = 0; // current DAC color index for writing
|
|
|
|
uint8_t dac_rd_index = 0; // current DAC color index for reading
|
|
|
|
uint8_t dac_mask = 0; // current DAC mask
|
|
|
|
int comp_index = 0; // current color component index
|
|
|
|
uint8_t color_buf[3] = {}; // buffer for storing DAC color components
|
2020-03-27 17:54:25 +00:00
|
|
|
};
|
2022-07-18 09:48:23 +00:00
|
|
|
|
2023-04-01 10:08:25 +00:00
|
|
|
#endif // ATI_RAGE_H
|