2020-02-28 16:04:28 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2023-02-04 16:57:46 +00:00
|
|
|
Copyright (C) 2018-23 divingkatae and maximum
|
2020-02-28 16:04:28 +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/>.
|
|
|
|
*/
|
|
|
|
|
2019-08-23 21:30:33 +00:00
|
|
|
#ifndef PCI_DEVICE_H
|
|
|
|
#define PCI_DEVICE_H
|
|
|
|
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <devices/common/mmiodevice.h>
|
|
|
|
#include <devices/common/pci/pcihost.h>
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <cinttypes>
|
2022-03-11 07:47:11 +00:00
|
|
|
#include <functional>
|
2022-04-13 21:01:27 +00:00
|
|
|
#include <memory>
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <string>
|
2023-02-04 16:57:46 +00:00
|
|
|
#include <vector>
|
2019-08-23 21:30:33 +00:00
|
|
|
|
2020-03-31 19:12:06 +00:00
|
|
|
/** PCI configuration space registers offsets */
|
2019-08-23 21:30:33 +00:00
|
|
|
enum {
|
2022-03-11 07:47:11 +00:00
|
|
|
PCI_CFG_DEV_ID = 0x00, // device and vendor IDs
|
|
|
|
PCI_CFG_STAT_CMD = 0x04, // command/status register
|
|
|
|
PCI_CFG_CLASS_REV = 0x08, // class code and revision ID
|
|
|
|
PCI_CFG_DWORD_3 = 0x0C, // BIST, HeaderType, Lat_Timer and Cache_Line_Size
|
|
|
|
PCI_CFG_BAR0 = 0x10, // base address register 0
|
|
|
|
PCI_CFG_BAR1 = 0x14, // base address register 1
|
|
|
|
PCI_CFG_BAR2 = 0x18, // base address register 2
|
|
|
|
PCI_CFG_BAR3 = 0x1C, // base address register 3
|
|
|
|
PCI_CFG_BAR4 = 0x20, // base address register 4
|
|
|
|
PCI_CFG_BAR5 = 0x24, // base address register 5
|
|
|
|
PCI_CFG_CIS_PTR = 0x28, // Cardbus CIS Pointer
|
|
|
|
PCI_CFG_SUBSYS_ID = 0x2C, // Subsysten IDs
|
|
|
|
PCI_CFG_ROM_BAR = 0x30, // expansion ROM base address
|
2022-08-22 09:39:07 +00:00
|
|
|
PCI_CFG_CAP_PTR = 0x34, // capabilities pointer
|
|
|
|
PCI_CFG_DWORD_14 = 0x38, // reserved
|
2022-03-11 07:47:11 +00:00
|
|
|
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt, Int_Pin and Int_Line registers
|
|
|
|
};
|
|
|
|
|
|
|
|
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
|
|
|
|
enum {
|
|
|
|
PCI_VENDOR_ATI = 0x1002,
|
2023-02-03 17:01:59 +00:00
|
|
|
PCI_VENDOR_DEC = 0x1011,
|
2022-03-11 07:47:11 +00:00
|
|
|
PCI_VENDOR_MOTOROLA = 0x1057,
|
|
|
|
PCI_VENDOR_APPLE = 0x106B,
|
2022-10-26 06:06:59 +00:00
|
|
|
PCI_VENDOR_NVIDIA = 0x10DE,
|
2019-08-23 21:30:33 +00:00
|
|
|
};
|
|
|
|
|
2022-12-11 21:37:14 +00:00
|
|
|
/** PCI BAR types */
|
2023-02-04 16:57:46 +00:00
|
|
|
enum PCIBarType : uint32_t {
|
|
|
|
Unused = 0,
|
|
|
|
Io_16_Bit,
|
|
|
|
Io_32_Bit,
|
|
|
|
Mem_20_Bit, // legacy type for < 1MB memory
|
|
|
|
Mem_32_Bit,
|
|
|
|
Mem_64_Bit_Lo,
|
|
|
|
Mem_64_Bit_Hi
|
2022-12-11 21:37:14 +00:00
|
|
|
};
|
2019-08-23 21:30:33 +00:00
|
|
|
|
2023-02-04 16:57:46 +00:00
|
|
|
typedef struct {
|
|
|
|
uint32_t bar_num;
|
|
|
|
uint32_t bar_cfg;
|
|
|
|
} BarConfig;
|
|
|
|
|
2019-08-23 21:30:33 +00:00
|
|
|
class PCIDevice : public MMIODevice {
|
|
|
|
public:
|
2022-03-11 07:47:11 +00:00
|
|
|
PCIDevice(std::string name);
|
2019-08-23 21:30:33 +00:00
|
|
|
virtual ~PCIDevice() = default;
|
|
|
|
|
2022-03-11 07:47:11 +00:00
|
|
|
virtual bool supports_io_space() {
|
2023-02-05 09:03:26 +00:00
|
|
|
return has_io_space;
|
2022-03-11 07:47:11 +00:00
|
|
|
};
|
2020-03-31 19:12:06 +00:00
|
|
|
|
|
|
|
/* I/O space access methods */
|
2020-05-12 18:55:45 +00:00
|
|
|
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
|
|
|
return false;
|
|
|
|
};
|
2020-03-31 19:12:06 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
|
|
|
return false;
|
|
|
|
};
|
2020-03-31 19:12:06 +00:00
|
|
|
|
2022-03-11 07:47:11 +00:00
|
|
|
// configuration space access 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
|
|
|
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
|
|
|
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
2022-03-11 07:47:11 +00:00
|
|
|
|
|
|
|
// plugin interface for using in the derived classes
|
|
|
|
std::function<uint16_t()> pci_rd_stat;
|
|
|
|
std::function<void(uint16_t)> pci_wr_stat;
|
|
|
|
std::function<uint16_t()> pci_rd_cmd;
|
|
|
|
std::function<void(uint16_t)> pci_wr_cmd;
|
|
|
|
std::function<uint8_t()> pci_rd_bist;
|
|
|
|
std::function<void(uint8_t)> pci_wr_bist;
|
|
|
|
std::function<uint8_t()> pci_rd_lat_timer;
|
|
|
|
std::function<void(uint8_t)> pci_wr_lat_timer;
|
|
|
|
std::function<uint8_t()> pci_rd_cache_lnsz;
|
|
|
|
std::function<void(uint8_t)> pci_wr_cache_lnsz;
|
|
|
|
|
|
|
|
std::function<void(int)> pci_notify_bar_change;
|
2019-08-23 21:30:33 +00:00
|
|
|
|
2022-04-13 21:01:27 +00:00
|
|
|
int attach_exp_rom_image(const std::string img_path);
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
virtual void set_host(PCIHost* host_instance) {
|
|
|
|
this->host_instance = host_instance;
|
|
|
|
};
|
2019-08-23 21:30:33 +00:00
|
|
|
|
2022-10-26 06:06:12 +00:00
|
|
|
virtual void set_multi_function(bool is_multi_function) {
|
|
|
|
this->hdr_type = is_multi_function ? (this->hdr_type | 0x80) : (this->hdr_type & 0x7f);
|
|
|
|
}
|
2023-02-05 08:39:37 +00:00
|
|
|
virtual void set_irq_pin(uint8_t irq_pin) {
|
|
|
|
this->irq_pin = irq_pin;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// MMIODevice methods
|
|
|
|
virtual uint32_t read(uint32_t rgn_start, uint32_t offset, int size) { return 0; }
|
|
|
|
virtual void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) { }
|
|
|
|
|
2019-08-23 21:30:33 +00:00
|
|
|
protected:
|
2022-03-11 07:47:11 +00:00
|
|
|
void set_bar_value(int bar_num, uint32_t value);
|
2023-02-04 16:57:46 +00:00
|
|
|
void setup_bars(std::vector<BarConfig> cfg_data);
|
2022-12-11 21:37:14 +00:00
|
|
|
void finish_config_bars();
|
2022-10-26 06:06:12 +00:00
|
|
|
void pci_wr_exp_rom_bar(uint32_t data);
|
2022-08-20 10:51:08 +00:00
|
|
|
void map_exp_rom_mem();
|
2022-10-26 06:06:12 +00:00
|
|
|
void unmap_exp_rom_mem();
|
2022-03-11 07:47:11 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
std::string pci_name; // human-readable device name
|
|
|
|
PCIHost* host_instance; // host bridge instance to call back
|
2022-03-11 07:47:11 +00:00
|
|
|
|
|
|
|
// PCI configuration space state
|
|
|
|
uint16_t vendor_id;
|
|
|
|
uint16_t device_id;
|
2023-02-02 01:21:23 +00:00
|
|
|
uint32_t class_rev; // class code and revision id
|
2022-03-11 07:47:11 +00:00
|
|
|
uint16_t status = 0;
|
|
|
|
uint16_t command = 0;
|
2022-10-26 06:06:12 +00:00
|
|
|
uint8_t hdr_type = 0; // header type, single function
|
2023-02-02 01:21:23 +00:00
|
|
|
uint8_t lat_timer = 0; // latency timer
|
|
|
|
uint8_t cache_ln_sz = 0; // cache line size
|
2022-03-11 07:47:11 +00:00
|
|
|
uint16_t subsys_id = 0;
|
|
|
|
uint16_t subsys_vndr = 0;
|
2022-08-22 09:39:07 +00:00
|
|
|
uint8_t cap_ptr = 0;
|
2022-03-11 07:47:11 +00:00
|
|
|
uint8_t max_lat = 0;
|
|
|
|
uint8_t min_gnt = 0;
|
|
|
|
uint8_t irq_pin = 0;
|
|
|
|
uint8_t irq_line = 0;
|
|
|
|
|
2023-02-05 09:03:26 +00:00
|
|
|
bool has_io_space = false;
|
2022-10-26 06:06:12 +00:00
|
|
|
int num_bars = 6;
|
2022-03-11 07:47:11 +00:00
|
|
|
uint32_t bars[6] = { 0 }; // base address registers
|
|
|
|
uint32_t bars_cfg[6] = { 0 }; // configuration values for base address registers
|
2023-02-04 16:57:46 +00:00
|
|
|
PCIBarType bars_typ[6] = { PCIBarType::Unused }; // types for base address registers
|
2022-04-13 21:01:27 +00:00
|
|
|
|
|
|
|
uint32_t exp_bar_cfg = 0; // expansion ROM configuration
|
|
|
|
uint32_t exp_rom_bar = 0; // expansion ROM base address register
|
|
|
|
uint32_t exp_rom_addr = 0; // expansion ROM base address
|
|
|
|
uint32_t exp_rom_size = 0; // expansion ROM size in bytes
|
|
|
|
|
|
|
|
std::unique_ptr<uint8_t[]> exp_rom_data;
|
2019-08-23 21:30:33 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) {
|
|
|
|
switch (details.size << 2 | details.offset) {
|
|
|
|
case 0x04: return (uint8_t) value;
|
|
|
|
case 0x05: return (uint8_t)(value >> 8);
|
|
|
|
case 0x06: return (uint8_t)(value >> 16);
|
|
|
|
case 0x07: return (uint8_t)(value >> 24);
|
|
|
|
|
|
|
|
case 0x08: return (uint16_t) value;
|
|
|
|
case 0x09: return (uint16_t) (value >> 8);
|
|
|
|
case 0x0a: return (uint16_t) (value >> 16);
|
|
|
|
case 0x0b: return (uint16_t)((value >> 24) | (value << 8));
|
|
|
|
|
|
|
|
case 0x10: return value;
|
|
|
|
case 0x11: return (value >> 8) | (value << 24);
|
|
|
|
case 0x12: return (value >> 16) | (value << 16);
|
|
|
|
case 0x13: return (value >> 24) | (value << 8);
|
|
|
|
|
|
|
|
default: return 0xffffffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 13:41:42 +00:00
|
|
|
#define SIZE_ARGS details.size == 4 ? 'l' : details.size == 2 ? 'w' : \
|
|
|
|
details.size == 1 ? 'b' : '0' + details.size
|
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
|
|
|
|
|
|
|
#define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER() \
|
|
|
|
do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \
|
|
|
|
VLOG_F( \
|
|
|
|
(~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \
|
|
|
|
"%s: read unimplemented config register @%02x.%c", \
|
|
|
|
this->name.c_str(), reg_offs + details.offset, \
|
|
|
|
SIZE_ARGS \
|
|
|
|
); \
|
|
|
|
} } while(0)
|
|
|
|
|
|
|
|
#define LOG_NAMED_CONFIG_REGISTER(reg_verb, reg_name) \
|
|
|
|
VLOG_F( \
|
|
|
|
(~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \
|
|
|
|
"%s: %s %s register @%02x.%c = %0*x", \
|
|
|
|
this->name.c_str(), reg_verb, reg_name, reg_offs + details.offset, \
|
|
|
|
SIZE_ARGS, \
|
|
|
|
details.size * 2, pci_cfg_log(value, details) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define LOG_READ_NAMED_CONFIG_REGISTER(reg_name) \
|
|
|
|
do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \
|
|
|
|
LOG_NAMED_CONFIG_REGISTER("read ", reg_name); \
|
|
|
|
} } while(0)
|
|
|
|
|
|
|
|
#define LOG_WRITE_NAMED_CONFIG_REGISTER(reg_name) \
|
|
|
|
LOG_NAMED_CONFIG_REGISTER("write", reg_name)
|
|
|
|
|
|
|
|
#define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER_WITH_VALUE() \
|
|
|
|
LOG_READ_NAMED_CONFIG_REGISTER("unimplemented config")
|
|
|
|
|
|
|
|
#define LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER() \
|
|
|
|
LOG_WRITE_NAMED_CONFIG_REGISTER("unimplemented config")
|
|
|
|
|
|
|
|
#define LOG_READ_NON_EXISTENT_PCI_DEVICE() \
|
|
|
|
LOG_F( \
|
|
|
|
ERROR, \
|
|
|
|
"%s err: read attempt from non-existent PCI device %02x:%02x.%x @%02x.%c", \
|
|
|
|
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
|
|
|
SIZE_ARGS \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define LOG_WRITE_NON_EXISTENT_PCI_DEVICE() \
|
|
|
|
LOG_F( \
|
|
|
|
ERROR, \
|
|
|
|
"%s err: write attempt to non-existent PCI device %02x:%02x.%x @%02x.%c = %0*x", \
|
|
|
|
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
|
|
|
SIZE_ARGS, \
|
|
|
|
details.size * 2, BYTESWAP_SIZED(value, details.size) \
|
|
|
|
)
|
|
|
|
|
2019-08-23 21:30:33 +00:00
|
|
|
#endif /* PCI_DEVICE_H */
|