mpc85xx: Port to RTEMS

This commit is contained in:
Sebastian Huber 2021-12-15 14:00:21 +01:00 committed by Christian Mauderer
parent 1e81e38a30
commit 17a3184081
9 changed files with 137 additions and 3 deletions

View File

@ -47,7 +47,9 @@ __FBSDID("$FreeBSD$");
#include <dev/pci/pcib_private.h>
#include <machine/bus.h>
#ifndef __rtems__
#include <machine/md_var.h>
#endif /* __rtems__ */
#include <machine/resource.h>
#include <vm/vm.h>
@ -79,9 +81,11 @@ static int ofw_pci_deactivate_resource(device_t, device_t, int, int,
static int ofw_pci_adjust_resource(device_t, device_t, int,
struct resource *, rman_res_t, rman_res_t);
#ifndef __rtems__
#ifdef __powerpc__
static bus_space_tag_t ofw_pci_bus_get_bus_tag(device_t, device_t);
#endif
#endif /* __rtems__ */
/*
* pcib interface
@ -118,9 +122,11 @@ static device_method_t ofw_pci_methods[] = {
DEVMETHOD(bus_activate_resource, ofw_pci_activate_resource),
DEVMETHOD(bus_deactivate_resource, ofw_pci_deactivate_resource),
DEVMETHOD(bus_adjust_resource, ofw_pci_adjust_resource),
#ifndef __rtems__
#ifdef __powerpc__
DEVMETHOD(bus_get_bus_tag, ofw_pci_bus_get_bus_tag),
#endif
#endif /* __rtems__ */
/* pcib interface */
DEVMETHOD(pcib_maxslots, ofw_pci_maxslots),
@ -531,9 +537,13 @@ ofw_pci_activate_resource(device_t bus, device_t child, int type, int rid,
printf("ofw_pci mapdev: start %jx, len %jd\n",
(rman_res_t)start, rman_get_size(res));
#ifndef __rtems__
tag = BUS_GET_BUS_TAG(child, child);
if (tag == NULL)
return (ENOMEM);
#else /* __rtems__ */
tag = 0;
#endif /* __rtems__ */
rman_set_bustag(res, tag);
rv = bus_space_map(tag, start,
@ -547,6 +557,7 @@ ofw_pci_activate_resource(device_t bus, device_t child, int type, int rid,
return (rman_activate_resource(res));
}
#ifndef __rtems__
#ifdef __powerpc__
static bus_space_tag_t
ofw_pci_bus_get_bus_tag(device_t bus, device_t child)
@ -555,20 +566,25 @@ ofw_pci_bus_get_bus_tag(device_t bus, device_t child)
return (&bs_le_tag);
}
#endif
#endif /* __rtems__ */
static int
ofw_pci_deactivate_resource(device_t bus, device_t child, int type, int rid,
struct resource *res)
{
#ifndef __rtems__
vm_size_t psize;
#endif /* __rtems__ */
if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY) {
return (bus_generic_deactivate_resource(bus, child, type, rid,
res));
}
#ifndef __rtems__
psize = rman_get_size(res);
pmap_unmapdev((vm_offset_t)rman_get_virtual(res), psize);
#endif /* __rtems__ */
return (rman_deactivate_resource(res));
}

View File

@ -3694,6 +3694,7 @@ pci_reserve_secbus(device_t bus, device_t dev, pcicfgregs *cfg,
}
break;
#ifndef __rtems__
case 0x00dd10de:
/* Compaq R3000 BIOS sets wrong subordinate bus number. */
if ((cp = kern_getenv("smbios.planar.maker")) == NULL)
@ -3715,6 +3716,7 @@ pci_reserve_secbus(device_t bus, device_t dev, pcicfgregs *cfg,
PCI_WRITE_CONFIG(bus, dev, sub_reg, sub_bus, 1);
}
break;
#endif /* __rtems__ */
}
if (bootverbose)

View File

@ -5588,7 +5588,6 @@ bus_data_generation_update(void)
bus_data_generation++;
}
#ifndef __rtems__
int
bus_free_resource(device_t dev, int type, struct resource *r)
{
@ -5597,6 +5596,7 @@ bus_free_resource(device_t dev, int type, struct resource *r)
return (bus_release_resource(dev, type, rman_get_rid(r), r));
}
#ifndef __rtems__
device_t
device_lookup_by_name(const char *name)
{

View File

@ -31,6 +31,9 @@
#ifndef _POWERPC_SPR_H_
#define _POWERPC_SPR_H_
#ifdef __rtems__
#define BOOKE
#endif /* __rtems__ */
#ifndef _LOCORE
#define mtspr(reg, val) \
__asm __volatile("mtspr %0,%1" : : "K"(reg), "r"(val))

View File

@ -273,6 +273,7 @@ law_pci_target(struct resource *res, int *trgt_mem, int *trgt_io)
return (rv);
}
#ifndef __rtems__
static void
l3cache_inval(void)
{
@ -320,6 +321,7 @@ mpc85xx_enable_l3_cache(void)
}
}
}
#endif /* __rtems__ */
int
mpc85xx_is_qoriq(void)
@ -333,6 +335,7 @@ mpc85xx_is_qoriq(void)
return (0);
}
#ifndef __rtems__
uint32_t
mpc85xx_get_platform_clock(void)
{
@ -359,3 +362,4 @@ mpc85xx_get_system_clock(void)
return (freq / 2);
}
#endif /* __rtems__ */

View File

@ -78,6 +78,9 @@ __FBSDID("$FreeBSD$");
#include <machine/intr_machdep.h>
#include <powerpc/mpc85xx/mpc85xx.h>
#ifdef __rtems__
#include <rtems/score/memory.h>
#endif /* __rtems__ */
#define REG_CFG_ADDR 0x0000
#define CONFIG_ACCESS_ENABLE 0x80000000
@ -233,7 +236,9 @@ static int fsl_pcib_release_msix(device_t dev, device_t child, int irq);
static int fsl_pcib_map_msi(device_t dev, device_t child,
int irq, uint64_t *addr, uint32_t *data);
#ifndef __rtems__
static vmem_t *msi_vmem; /* Global MSI vmem, holds all MSI ranges. */
#endif /* __rtems__ */
/*
* Bus interface definitions.
@ -414,6 +419,8 @@ fsl_pcib_attach(device_t dev)
return (ENXIO);
}
fsl_pcib_err_init(dev);
/* Setup interrupt handler */
error = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_MISC | INTR_MPSAFE,
NULL, fsl_pcib_err_intr, dev, &sc->sc_ih);
@ -429,8 +436,6 @@ fsl_pcib_attach(device_t dev)
return (ENXIO);
}
fsl_pcib_err_init(dev);
return (ofw_pci_attach(dev));
err:
@ -751,8 +756,15 @@ fsl_pcib_decode_win(phandle_t node, struct fsl_pcib_softc *sc)
fsl_pcib_inbound(sc, 1, -1, 0, 0, 0);
fsl_pcib_inbound(sc, 2, -1, 0, 0, 0);
#ifndef __rtems__
fsl_pcib_inbound(sc, 3, PIWAR_TRGT_LOCAL, 0,
ptoa(Maxmem), 0);
#else /* __rtems__ */
const Memory_Information *mem = _Memory_Get();
const Memory_Area *area = _Memory_Get_area( mem, 0 );
fsl_pcib_inbound(sc, 3, PIWAR_TRGT_LOCAL, 0,
(uintptr_t)_Memory_Get_end(area), 0);
#endif /* __rtems__ */
/* Direct-map the CCSR for MSIs. */
/* Freescale PCIe 2.x has a dedicated MSI window. */
@ -770,6 +782,7 @@ fsl_pcib_decode_win(phandle_t node, struct fsl_pcib_softc *sc)
static int fsl_pcib_alloc_msi(device_t dev, device_t child,
int count, int maxcount, int *irqs)
{
#ifndef __rtems__
struct fsl_pcib_softc *sc;
vmem_addr_t start;
int err, i;
@ -786,6 +799,9 @@ static int fsl_pcib_alloc_msi(device_t dev, device_t child,
for (i = 0; i < count; i++)
irqs[i] = start + i;
#else /* __rtems__ */
BSD_ASSERT(0);
#endif /* __rtems__ */
return (0);
}
@ -793,10 +809,14 @@ static int fsl_pcib_alloc_msi(device_t dev, device_t child,
static int fsl_pcib_release_msi(device_t dev, device_t child,
int count, int *irqs)
{
#ifndef __rtems__
if (msi_vmem == NULL)
return (ENODEV);
vmem_xfree(msi_vmem, irqs[0], count);
#else /* __rtems__ */
BSD_ASSERT(0);
#endif /* __rtems__ */
return (0);
}
@ -869,7 +889,11 @@ fsl_msi_intr_filter(void *priv)
i = 0;
while (reg != 0) {
if (reg & 1)
#ifndef __rtems__
powerpc_dispatch_intr(data->vectors[i], NULL);
#else /* __rtems__ */
BSD_ASSERT(0);
#endif /* __rtems__ */
reg >>= 1;
i++;
}
@ -897,8 +921,10 @@ fsl_msi_attach(device_t dev)
sc = device_get_softc(dev);
#ifndef __rtems__
if (msi_vmem == NULL)
msi_vmem = vmem_create("MPIC MSI", 0, 0, 1, 0, M_BESTFIT | M_WAITOK);
#endif /* __rtems__ */
/* Manually play with resource entries. */
sc->sc_base = bus_get_resource_start(dev, SYS_RES_MEMORY, 0);
@ -916,11 +942,13 @@ fsl_msi_attach(device_t dev)
bus_setup_intr(dev, irq->res, INTR_TYPE_MISC | INTR_MPSAFE,
fsl_msi_intr_filter, NULL, irq, &irq->cookie);
}
#ifndef __rtems__
sc->sc_map.irq_base = powerpc_register_pic(dev, ofw_bus_get_node(dev),
FSL_NUM_MSIS, 0, 0);
/* Let vmem and the IRQ subsystem work their magic for allocations. */
vmem_add(msi_vmem, sc->sc_map.irq_base, FSL_NUM_MSIS, M_WAITOK);
#endif /* __rtems__ */
SLIST_INSERT_HEAD(&fsl_msis, &sc->sc_map, slist);

View File

@ -177,6 +177,7 @@ class rtems(builder.Module):
'local/ofw_if.c',
'local/pcib_if.c',
'local/pci_if.c',
'local/pic_if.c',
'local/xdma_if.c',
'local/usb_if.c',
'local/mmcbus_if.c',
@ -3084,17 +3085,21 @@ class pci(builder.Module):
'sys/dev/pci/pcib_support.c',
'sys/dev/pci/pci.c',
'sys/dev/pci/pci_pci.c',
'sys/dev/pci/pci_subr.c',
'sys/dev/pci/pci_user.c',
'sys/dev/ofw/ofwpci.c',
],
mm.generator['source']()
)
self.addKernelSpaceHeaderFiles(
[
'sys/dev/ofw/ofwpci.h',
'sys/dev/pci/pcib_private.h',
'sys/dev/pci/pci_private.h',
'sys/dev/pci/pcireg.h',
'sys/dev/pci/pcivar.h',
'sys/dev/pci/pcivar.h',
'sys/powerpc/mpc85xx/mpc85xx.h',
]
)
self.addCPUDependentFreeBSDHeaderFiles(
@ -3103,6 +3108,9 @@ class pci(builder.Module):
'sys/x86/include/legacyvar.h',
'sys/x86/include/bus.h',
'sys/x86/include/pci_cfgreg.h',
'sys/powerpc/include/platformvar.h',
'sys/powerpc/include/hid.h',
'sys/powerpc/include/pio.h',
]
)
self.addCPUDependentFreeBSDSourceFiles(
@ -3113,6 +3121,23 @@ class pci(builder.Module):
],
mm.generator['source']()
)
self.addCPUDependentFreeBSDSourceFiles(
[ 'powerpc' ],
[
'sys/powerpc/mpc85xx/mpc85xx.c',
'sys/powerpc/mpc85xx/pci_mpc85xx.c',
'sys/powerpc/mpc85xx/pci_mpc85xx_pcib.c',
'sys/powerpc/ofw/ofw_pcib_pci.c',
],
mm.generator['source']()
)
self.addCPUDependentRTEMSSourceFiles(
[ 'powerpc' ],
[
'sys/powerpc/platform_mpc85xx.c',
],
mm.generator['source']()
)
#

View File

@ -255,10 +255,18 @@ SYSINIT_DRIVER_REFERENCE(ukphy, miibus);
#include <bsp/irq.h>
RTEMS_BSD_DEFINE_NEXUS_DEVICE(ofwbus, 0, 0, NULL);
SYSINIT_DRIVER_REFERENCE(simplebus, ofwbus);
SYSINIT_DRIVER_REFERENCE(tsec, simplebus);
SYSINIT_DRIVER_REFERENCE(ukphy, miibus);
#ifdef RTEMS_BSD_MODULE_PCI
SYSINIT_DRIVER_REFERENCE(pcib, ofwbus);
SYSINIT_DRIVER_REFERENCE(pci, pcib);
SYSINIT_DRIVER_REFERENCE(pcib, pci);
SYSINIT_DRIVER_REFERENCE(rcpcib, pci);
#endif
#endif /* QORIQ_CHIP_IS_T_VARIANT(QORIQ_CHIP_VARIANT) */
#elif defined(LIBBSP_POWERPC_TQM8XX_BSP_H)

View File

@ -0,0 +1,48 @@
#include <machine/rtems-bsd-kernel-space.h>
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2008-2012 Semihalf.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/mutex.h>
#include <sys/bus.h>
#include <powerpc/mpc85xx/mpc85xx.h>
#include <bsp.h>
#ifdef LIBBSP_POWERPC_QORIQ_BSP_H
#include <bsp/qoriq.h>
vm_paddr_t ccsrbar_pa = (vm_paddr_t)&qoriq;
vm_offset_t ccsrbar_va = (vm_offset_t)&qoriq;
vm_size_t ccsrbar_size = sizeof(qoriq);
#endif /* LIBBSP_POWERPC_QORIQ_BSP_H */