Skip to content

Commit

Permalink
newpci: propose a way to find the busmaster space
Browse files Browse the repository at this point in the history
  • Loading branch information
galibert committed Feb 19, 2024
1 parent fce4d1f commit a9f8830
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 71 deletions.
3 changes: 1 addition & 2 deletions src/devices/machine/gt64xxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ void gt64xxx_device::device_start()
{
pci_host_device::device_start();
m_cpu_space = &m_cpu->space(AS_PCI_CONFIG);
memory_space = &space(AS_PCI_MEM);
io_space = &space(AS_PCI_IO);
set_spaces(&space(AS_PCI_MEM), &space(AS_PCI_IO));

memory_window_start = 0;
memory_window_end = 0xffffffff;
Expand Down
3 changes: 1 addition & 2 deletions src/devices/machine/i82439hx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ void i82439hx_host_device::set_ram_size(int _ram_size)
void i82439hx_host_device::device_start()
{
pci_host_device::device_start();
memory_space = &cpu->space(AS_PROGRAM);
io_space = &cpu->space(AS_IO);
set_spaces(&cpu->space(AS_PROGRAM), &cpu->space(AS_IO));

memory_window_start = 0;
memory_window_end = 0xffffffff;
Expand Down
3 changes: 1 addition & 2 deletions src/devices/machine/i82439tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ void i82439tx_host_device::set_ram_size(int _ram_size)
void i82439tx_host_device::device_start()
{
pci_host_device::device_start();
memory_space = &cpu->space(AS_PROGRAM);
io_space = &cpu->space(AS_IO);
set_spaces(&cpu->space(AS_PROGRAM), &cpu->space(AS_IO));

memory_window_start = 0;
memory_window_end = 0xffffffff;
Expand Down
3 changes: 1 addition & 2 deletions src/devices/machine/i82875p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ uint8_t i82875p_host_device::capptr_r()
void i82875p_host_device::device_start()
{
pci_host_device::device_start();
memory_space = &cpu->space(AS_PROGRAM);
io_space = &cpu->space(AS_IO);
set_spaces(&cpu->space(AS_PROGRAM), &cpu->space(AS_IO));

memory_window_start = 0;
memory_window_end = 0xffffffff;
Expand Down
3 changes: 1 addition & 2 deletions src/devices/machine/mediagx_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ device_memory_interface::space_config_vector mediagx_host_device::memory_space_c
void mediagx_host_device::device_start()
{
pci_host_device::device_start();
memory_space = &m_host_cpu->space(AS_PROGRAM);
io_space = &m_host_cpu->space(AS_IO);
set_spaces(&m_host_cpu->space(AS_PROGRAM), &m_host_cpu->space(AS_IO));

memory_window_start = 0;
memory_window_end = 0xffffffff;
Expand Down
3 changes: 1 addition & 2 deletions src/devices/machine/mpc106.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ void mpc106_host_device::device_start()
{
pci_host_device::device_start();
m_cpu_space = &m_cpu->space(AS_PCI_CONFIG);
memory_space = &space(AS_PCI_MEM);
io_space = &space(AS_PCI_IO);
set_spaces(&space(AS_PCI_MEM), &space(AS_PCI_IO));

memory_window_start = 0;
memory_window_end = 0xffffffff;
Expand Down
3 changes: 1 addition & 2 deletions src/devices/machine/mv6436x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,7 @@ void mv64361_pci_host_device::device_start()
{
pci_host_device::device_start();

memory_space = &space(AS_PCI_MEM);
io_space = &space(AS_PCI_IO);
set_spaces(&space(AS_PCI_MEM), &space(AS_PCI_IO));

memory_window_start = 0;
memory_window_end = 0xffffffff;
Expand Down
9 changes: 8 additions & 1 deletion src/devices/machine/pci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,12 @@ void pci_host_device::io_configuration_access_map(address_map &map)
map(0xcfc, 0xcff).rw(FUNC(pci_host_device::config_data_r), FUNC(pci_host_device::config_data_w));
}

void pci_host_device::set_spaces(address_space *memory, address_space *io, address_space *busmaster)
{
memory_space = memory;
io_space = io ? io : memory;
m_pci_root->set_pci_busmaster_space(busmaster ? busmaster : memory);
}

pci_host_device::pci_host_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
: pci_bridge_device(mconfig, type, tag, owner, clock)
Expand Down Expand Up @@ -1012,7 +1018,8 @@ void pci_host_device::root_config_write(uint8_t bus, uint8_t device, uint16_t re
pci_root_device::pci_root_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, PCI_ROOT, tag, owner, clock),
m_pin_mapper(*this),
m_irq_handler(*this)
m_irq_handler(*this),
m_pci_busmaster_space(nullptr)
{
}

Expand Down
20 changes: 17 additions & 3 deletions src/devices/machine/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class pci_device : public device_t {
void set_map_address(int id, uint64_t adr);
void set_map_size(int id, uint64_t size);
void set_map_flags(int id, int flags);

inline address_space *get_pci_busmaster_space() const;
};

class agp_device : public pci_device {
Expand Down Expand Up @@ -243,6 +245,8 @@ class pci_host_device : public pci_bridge_device {
public:
void io_configuration_access_map(address_map &map);

void set_spaces(address_space *memory, address_space *io = nullptr, address_space *busmaster = nullptr);

protected:
pci_host_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

Expand All @@ -264,12 +268,13 @@ class pci_host_device : public pci_bridge_device {

void regenerate_mapping();

address_space *memory_space, *io_space;

uint64_t memory_window_start, memory_window_end, memory_offset;
uint64_t io_window_start, io_window_end, io_offset;

uint32_t config_address;

private:
address_space *memory_space, *io_space;
};

using pci_pin_mapper = device_delegate<int (int)>;
Expand All @@ -285,16 +290,25 @@ class pci_root_device : public device_t {
void set_pin_mapper(pci_pin_mapper &&mapper) { m_pin_mapper = std::move(mapper); }
void set_irq_handler(pci_irq_handler &&handler) { m_irq_handler = std::move(handler); }

address_space *get_pci_busmaster_space() const { return m_pci_busmaster_space; }

void set_pci_busmaster_space(address_space *space) { m_pci_busmaster_space = space; }

protected:
virtual void device_start() override;
virtual void device_reset() override;

private:
pci_pin_mapper m_pin_mapper;
pci_irq_handler m_irq_handler;

address_space *m_pci_busmaster_space;
};

address_space *pci_device::get_pci_busmaster_space() const
{
return m_pci_root->get_pci_busmaster_space();
}

DECLARE_DEVICE_TYPE(PCI_ROOT, pci_root_device)
DECLARE_DEVICE_TYPE(PCI_BRIDGE, pci_bridge_device)

Expand Down
3 changes: 1 addition & 2 deletions src/devices/machine/sis630_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ void sis630_host_device::device_start()
io_window_end = 0xffff;
io_offset = 0;

memory_space = &m_host_cpu->space(AS_PROGRAM);
io_space = &m_host_cpu->space(AS_IO);
set_spaces(&m_host_cpu->space(AS_PROGRAM), &m_host_cpu->space(AS_IO));
add_map(8*1024*1024, M_MEM, FUNC(sis630_host_device::memory_map));

m_ram.resize(m_ram_size/4);
Expand Down
3 changes: 1 addition & 2 deletions src/devices/machine/sis85c496.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ void sis85c496_host_device::device_start()
{
pci_host_device::device_start();

memory_space = &m_maincpu->space(AS_PROGRAM);
io_space = &m_maincpu->space(AS_IO);
set_spaces(&m_maincpu->space(AS_PROGRAM), &m_maincpu->space(AS_IO));

memory_window_start = 0;
memory_window_end = 0xffffffff;
Expand Down
3 changes: 1 addition & 2 deletions src/devices/machine/vrc4373.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ void vrc4373_device::device_start()
pci_host_device::device_start();

m_cpu_space = &m_cpu->space(AS_PCI_CONFIG);
memory_space = &space(AS_PCI_MEM);
io_space = &space(AS_PCI_IO);
set_spaces(&space(AS_PCI_MEM), &space(AS_PCI_IO));
is_multifunction_device = false;

std::fill(std::begin(m_cpu_regs), std::end(m_cpu_regs), 0);
Expand Down
3 changes: 1 addition & 2 deletions src/devices/machine/vrc5074.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ void vrc5074_device::device_start()
{
pci_host_device::device_start();
m_cpu_space = &m_cpu->space(AS_PROGRAM);
memory_space = &space(AS_DATA);
io_space = &space(AS_IO);
set_spaces(&space(AS_DATA), &space(AS_IO));

memory_window_start = 0;
memory_window_end = 0xffffffff;
Expand Down
3 changes: 1 addition & 2 deletions src/mame/apple/bandit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ void bandit_host_device::device_start()
{
pci_host_device::device_start();
m_cpu_space = &m_cpu->space(AS_PCI_CONFIG);
memory_space = &space(AS_PCI_MEM);
io_space = &space(AS_PCI_IO);
set_spaces(&space(AS_PCI_MEM), &space(AS_PCI_IO));

memory_window_start = 0;
memory_window_end = 0xffffffff;
Expand Down
29 changes: 15 additions & 14 deletions src/mame/apple/heathrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void grandcentral_device::device_add_mconfig(machine_config &config)
{
macio_device::device_add_mconfig(config);

DBDMA_CHANNEL(config, m_dma_scsi1, 0, m_pci_memory);
DBDMA_CHANNEL(config, m_dma_scsi1, 0);
m_dma_scsi1->irq_callback().set(FUNC(macio_device::set_irq_line<10>));
}

Expand Down Expand Up @@ -217,7 +217,6 @@ macio_device::macio_device(const machine_config &mconfig, device_type type, cons
m_dma_sccbrx(*this, "dma_sccb_rx"),
m_dma_audio_in(*this, "dma_audin"),
m_dma_audio_out(*this, "dma_audout"),
m_pci_memory(*this, ":pci:00.0", AS_DATA),
m_cur_floppy(nullptr),
m_hdsel(0)
{
Expand Down Expand Up @@ -264,16 +263,18 @@ paddington_device::paddington_device(const machine_config &mconfig, const char *

void macio_device::common_init()
{
m_dma_scsi->set_address_space(m_pci_memory);
m_dma_floppy->set_address_space(m_pci_memory);
m_dma_sccatx->set_address_space(m_pci_memory);
m_dma_sccarx->set_address_space(m_pci_memory);
m_dma_sccbtx->set_address_space(m_pci_memory);
m_dma_sccbrx->set_address_space(m_pci_memory);
m_dma_audio_in->set_address_space(m_pci_memory);
m_dma_audio_out->set_address_space(m_pci_memory);

pci_device::device_start();

address_space *bm = get_pci_busmaster_space();
m_dma_scsi->set_address_space(bm);
m_dma_floppy->set_address_space(bm);
m_dma_sccatx->set_address_space(bm);
m_dma_sccarx->set_address_space(bm);
m_dma_sccbtx->set_address_space(bm);
m_dma_sccbrx->set_address_space(bm);
m_dma_audio_in->set_address_space(bm);
m_dma_audio_out->set_address_space(bm);

command = 2; // enable our memory range
revision = 1;

Expand All @@ -296,7 +297,7 @@ void grandcentral_device::device_start()
add_map(0x20000, M_MEM, FUNC(grandcentral_device::map)); // Grand Central only has 128K of BAR space, the others have 512K
set_ids(0x106b0002, 0x01, 0xff000001, 0x000000);

m_dma_scsi1->set_address_space(m_pci_memory);
m_dma_scsi1->set_address_space(get_pci_busmaster_space());
}

void ohare_device::device_start()
Expand All @@ -306,8 +307,8 @@ void ohare_device::device_start()
set_ids(0x106b0007, 0x01, 0xff0000, 0x000000);
save_item(NAME(m_nvram));

m_dma_ata0->set_address_space(m_pci_memory);
m_dma_ata1->set_address_space(m_pci_memory);
m_dma_ata0->set_address_space(get_pci_busmaster_space());
m_dma_ata1->set_address_space(get_pci_busmaster_space());
}

void heathrow_device::device_start()
Expand Down
2 changes: 0 additions & 2 deletions src/mame/apple/heathrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class macio_device : public pci_device
auto codec_w_callback() { return write_codec.bind(); }

template <typename... T> void set_maincpu_tag(T &&... args) { m_maincpu.set_tag(std::forward<T>(args)...); }
template <typename... T> void set_pci_root_tag(T &&... args) { m_pci_memory.set_tag(std::forward<T>(args)...); }

void cb1_w(int state);
void cb2_w(int state);
Expand Down Expand Up @@ -86,7 +85,6 @@ class macio_device : public pci_device
required_device<z80scc_device> m_scc;
required_device<dbdma_device> m_dma_scsi, m_dma_floppy, m_dma_sccatx, m_dma_sccarx;
required_device<dbdma_device> m_dma_sccbtx, m_dma_sccbrx, m_dma_audio_in, m_dma_audio_out;
required_address_space m_pci_memory;

private:
floppy_image_device *m_cur_floppy = nullptr;
Expand Down
1 change: 0 additions & 1 deletion src/mame/apple/imacg3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ void imac_state::imac(machine_config &config)

paddington_device &paddington(PADDINGTON(config, "pci:10.0", 0));
paddington.set_maincpu_tag("maincpu");
paddington.set_pci_root_tag(":pci:00.0", AS_DATA);
paddington.irq_callback().set(FUNC(imac_state::irq_w));

atirage_device &ati(ATI_RAGEIIC(config, "pci:12.0", 14.318181_MHz_XTAL));
Expand Down
1 change: 0 additions & 1 deletion src/mame/apple/pippin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ void pippin_state::pippin(machine_config &config)

grandcentral_device &grandcentral(GRAND_CENTRAL(config, "pci:0d.0", 0));
grandcentral.set_maincpu_tag("maincpu");
grandcentral.set_pci_root_tag(":pci:00.0", AS_DATA);
grandcentral.irq_callback().set(FUNC(pippin_state::irq_w));

awacs_macrisc_device &awacs(AWACS_MACRISC(config, "codec", 45.1584_MHz_XTAL / 2));
Expand Down
1 change: 0 additions & 1 deletion src/mame/apple/powermacg3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ void pwrmacg3_state::pwrmacg3(machine_config &config)

heathrow_device &heathrow(HEATHROW(config, "pci:10.0", 0));
heathrow.set_maincpu_tag("maincpu");
heathrow.set_pci_root_tag(":pci:00.0", AS_DATA);

// Apple's documentation says systems with the 4.0f2 ROM use a Rage II+, but
// the 4.0f2 ROM won't init the Rage if the PCI ID is 4755 (II+), only 4754 (Rage II).
Expand Down
3 changes: 1 addition & 2 deletions src/mame/pc/nforcepc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ void crush11_host_device::device_start()
{
pci_host_device::device_start();
set_multifunction_device(true);
memory_space = &cpu->space(AS_DATA);
io_space = &cpu->space(AS_IO);
set_spaces(&cpu->space(AS_DATA), &cpu->space(AS_IO));

memory_window_start = 0;
memory_window_end = 0xffffffff;
Expand Down
25 changes: 12 additions & 13 deletions src/mame/sega/315-6154.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ sega_315_6154_device::sega_315_6154_device(const machine_config &mconfig, const
void sega_315_6154_device::device_start()
{
pci_host_device::device_start();
memory_space = &space(AS_PCI_MEMORY);
set_spaces(&space(AS_PCI_MEMORY));
// never unmap addresses lower than start
memory_window_start = 0x80000000;
memory_window_end = 0xffffffff;
memory_offset = 0;

m_configuration = &space(AS_PCI_CONFIG);

io_space = memory_space;
io_window_start = 0xc0000000;
io_window_end = 0xc000ffff;
io_offset = 0xc0000000;
Expand Down Expand Up @@ -112,7 +111,7 @@ void sega_315_6154_device::registers_w(offs_t offset, u32 data, u32 mem_mask)
logerror("got dma transfer request from 0x%08x to 0x%08x size 0x%08x bytes\n", s, d, l << 2);
while (l != 0)
{
memory_space->write_dword(d, memory_space->read_dword(s));
space(AS_PCI_MEMORY).write_dword(d, space(AS_PCI_MEMORY).read_dword(s));
s += 4;
d += 4;
l--;
Expand All @@ -123,7 +122,7 @@ void sega_315_6154_device::registers_w(offs_t offset, u32 data, u32 mem_mask)
}

template<int Aperture>
u32 sega_315_6154_device::aperture_r(address_space &space, offs_t offset, u32 mem_mask)
u32 sega_315_6154_device::aperture_r(offs_t offset, u32 mem_mask)
{
const u32 destination_offset = offset & 0x3fffff;
const int destination = (offset >> 22) & 3;
Expand All @@ -133,15 +132,15 @@ u32 sega_315_6154_device::aperture_r(address_space &space, offs_t offset, u32 me
return m_configuration->read_dword(destination_offset << 2, mem_mask);
if ((Aperture == 1) && (destination == 0) && (m_useconfig_18x == true))
return m_configuration->read_dword(destination_offset << 2, mem_mask);
return memory_space->read_dword(m_bases[index] + (destination_offset << 2), mem_mask);
return space(AS_PCI_MEMORY).read_dword(m_bases[index] + (destination_offset << 2), mem_mask);
}

template u32 sega_315_6154_device::aperture_r<0>(address_space &space, offs_t offset, u32 mem_mask);
template u32 sega_315_6154_device::aperture_r<1>(address_space &space, offs_t offset, u32 mem_mask);
template u32 sega_315_6154_device::aperture_r<2>(address_space &space, offs_t offset, u32 mem_mask);
template u32 sega_315_6154_device::aperture_r<0>(offs_t offset, u32 mem_mask);
template u32 sega_315_6154_device::aperture_r<1>(offs_t offset, u32 mem_mask);
template u32 sega_315_6154_device::aperture_r<2>(offs_t offset, u32 mem_mask);

template<int Aperture>
void sega_315_6154_device::aperture_w(address_space &space, offs_t offset, u32 data, u32 mem_mask)
void sega_315_6154_device::aperture_w(offs_t offset, u32 data, u32 mem_mask)
{
const u32 destination_offset = offset & 0x3fffff;
const int destination = (offset >> 22) & 3;
Expand All @@ -157,9 +156,9 @@ void sega_315_6154_device::aperture_w(address_space &space, offs_t offset, u32 d
m_configuration->write_dword(destination_offset << 2, data, mem_mask);
return;
}
memory_space->write_dword(m_bases[index] + (destination_offset << 2), data, mem_mask);
space(AS_PCI_MEMORY).write_dword(m_bases[index] + (destination_offset << 2), data, mem_mask);
}

template void sega_315_6154_device::aperture_w<0>(address_space &space, offs_t offset, u32 data, u32 mem_mask);
template void sega_315_6154_device::aperture_w<1>(address_space &space, offs_t offset, u32 data, u32 mem_mask);
template void sega_315_6154_device::aperture_w<2>(address_space &space, offs_t offset, u32 data, u32 mem_mask);
template void sega_315_6154_device::aperture_w<0>(offs_t offset, u32 data, u32 mem_mask);
template void sega_315_6154_device::aperture_w<1>(offs_t offset, u32 data, u32 mem_mask);
template void sega_315_6154_device::aperture_w<2>(offs_t offset, u32 data, u32 mem_mask);
Loading

0 comments on commit a9f8830

Please sign in to comment.