2020-02-28 16:04:28 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2023-02-01 23:21:36 +00:00
|
|
|
Copyright (C) 2018-23 divingkatae and maximum
|
2020-02-28 16:04:28 +00:00
|
|
|
(theweirdo) spatium
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-02-28 16:04:28 +00:00
|
|
|
(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/>.
|
|
|
|
*/
|
2019-08-21 06:33:01 +00:00
|
|
|
|
2023-02-01 23:21:36 +00:00
|
|
|
/** MPC106 (Grackle) definitions.
|
2019-08-21 06:33:01 +00:00
|
|
|
|
2019-08-23 19:30:30 +00:00
|
|
|
Grackle IC is a combined memory and PCI controller manufactured by Motorola.
|
2019-08-21 06:33:01 +00:00
|
|
|
It's the central device in the Gossamer architecture.
|
|
|
|
Manual: https://www.nxp.com/docs/en/reference-manual/MPC106UM.pdf
|
|
|
|
|
2023-12-03 09:12:37 +00:00
|
|
|
This code emulates as much functionality as needed to run Power Mac Beige G3.
|
2019-08-21 06:33:01 +00:00
|
|
|
This implies that
|
|
|
|
- we only support address map B
|
|
|
|
- our virtual device reports revision 4.0 as expected by machine firmware
|
|
|
|
*/
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2023-02-01 23:21:36 +00:00
|
|
|
#ifndef MPC106_H
|
|
|
|
#define MPC106_H
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <devices/common/pci/pcidevice.h>
|
|
|
|
#include <devices/common/pci/pcihost.h>
|
2023-09-19 00:24:50 +00:00
|
|
|
#include <machines/machinebase.h>
|
2021-10-23 18:17:47 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <cinttypes>
|
2022-07-17 03:33:06 +00:00
|
|
|
#include <memory>
|
2019-08-21 06:33:01 +00:00
|
|
|
|
2023-09-19 00:24:50 +00:00
|
|
|
class InterruptCtrl;
|
|
|
|
|
2023-02-01 23:21:36 +00:00
|
|
|
/** Grackle configuration space registers. */
|
|
|
|
enum GrackleReg : uint32_t {
|
|
|
|
CFG10 = 0x40, // bus # + subordinate bus # + disconnect counter
|
|
|
|
PMCR1 = 0x70, // power management config 1
|
|
|
|
MSAR1 = 0x80, // memory starting address 1
|
|
|
|
MSAR2 = 0x84, // memory starting address 2
|
|
|
|
EMSAR1 = 0x88, // extended memory starting address 1
|
|
|
|
EMSAR2 = 0x8C, // extended memory starting address 2
|
|
|
|
MEAR1 = 0x90, // memory ending address 1
|
|
|
|
MEAR2 = 0x94, // memory ending address 2
|
|
|
|
EMEAR1 = 0x98, // extended memory ending address 1
|
|
|
|
EMEAR2 = 0x9C, // extended memory ending address 2
|
|
|
|
MBER = 0xA0, // memory bank enable
|
|
|
|
PICR1 = 0xA8, // processor interface configuration 1
|
|
|
|
PICR2 = 0xAC, // processor interface configuration 2
|
|
|
|
MCCR1 = 0xF0, // memory control configuration 1
|
|
|
|
MCCR2 = 0xF4, // memory control configuration 2
|
|
|
|
MCCR3 = 0xF8, // memory control configuration 3
|
|
|
|
MCCR4 = 0xFC // memory control configuration 4
|
|
|
|
};
|
|
|
|
|
|
|
|
/* MCCR1 bit definitions. */
|
|
|
|
enum {
|
|
|
|
MEMGO = 1 << 19,
|
|
|
|
};
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
class MPC106 : public MemCtrlBase, public PCIDevice, public PCIHost {
|
2019-08-21 06:33:01 +00:00
|
|
|
public:
|
|
|
|
MPC106();
|
2022-01-16 20:30:43 +00:00
|
|
|
~MPC106() = default;
|
2020-03-14 13:23:46 +00:00
|
|
|
|
2022-07-17 03:33:06 +00:00
|
|
|
static std::unique_ptr<HWComponent> create() {
|
|
|
|
return std::unique_ptr<MPC106>(new MPC106());
|
|
|
|
}
|
|
|
|
|
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);
|
2019-08-21 06:33:01 +00:00
|
|
|
|
2023-09-19 00:24:50 +00:00
|
|
|
virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev);
|
|
|
|
|
2022-08-19 18:07:22 +00:00
|
|
|
int device_postinit();
|
|
|
|
|
2019-08-21 06:33:01 +00:00
|
|
|
protected:
|
2019-08-23 19:30:30 +00:00
|
|
|
/* my own PCI configuration registers access */
|
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);
|
2019-08-23 19:30:30 +00:00
|
|
|
|
2019-10-07 01:21:01 +00:00
|
|
|
void setup_ram(void);
|
|
|
|
|
2019-08-21 06:33:01 +00:00
|
|
|
private:
|
2023-02-07 13:41:42 +00:00
|
|
|
inline void cfg_setup(uint32_t offset, int size, int &bus_num, int &dev_num,
|
|
|
|
int &fun_num, uint8_t ®_offs, AccessDetails &details,
|
2023-06-08 14:09:29 +00:00
|
|
|
PCIBase *&device);
|
2022-10-26 06:06:12 +00:00
|
|
|
|
2019-08-21 06:33:01 +00:00
|
|
|
uint32_t config_addr;
|
2023-02-01 23:21:36 +00:00
|
|
|
|
|
|
|
uint16_t pmcr1 = 0; // power management config 1
|
|
|
|
uint8_t pmcr2 = 0; // power management config 2
|
|
|
|
uint8_t odcr = 0xCD; // output driver control
|
|
|
|
uint32_t picr1 = 0xFF100010; // ROM on CPU bus, address map B, CPU type = MPC601
|
|
|
|
uint32_t picr2 = 0x000C060C;
|
|
|
|
uint32_t mccr1 = 0xFF820000; // 64bit ROM bus
|
|
|
|
uint32_t mccr2 = 3;
|
|
|
|
uint32_t mccr3 = 0;
|
|
|
|
uint32_t mccr4 = 0x00100000;
|
|
|
|
|
|
|
|
uint32_t mem_start[2] = {};
|
|
|
|
uint32_t ext_mem_start[2] = {};
|
|
|
|
uint32_t mem_end[2] = {};
|
|
|
|
uint32_t ext_mem_end[2] = {};
|
|
|
|
uint8_t mem_bank_en = 0;
|
2023-09-19 00:24:50 +00:00
|
|
|
|
|
|
|
// interrupt related stuff
|
|
|
|
InterruptCtrl* int_ctrl = nullptr;
|
|
|
|
uint32_t irq_id_PCI_A = 0;
|
|
|
|
uint32_t irq_id_PCI_B = 0;
|
|
|
|
uint32_t irq_id_PCI_C = 0;
|
|
|
|
uint32_t irq_id_PCI_GPU = 0;
|
|
|
|
uint32_t irq_id_PCI_PERCH = 0;
|
2019-08-21 06:33:01 +00:00
|
|
|
};
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2023-02-01 23:21:36 +00:00
|
|
|
#endif // MPC106_H
|