mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-15 19:44:37 +08:00
Added nexus_setup_intr support and did some cleanup.
This commit is contained in:
@@ -514,6 +514,7 @@ rtems.addRTEMSHeaderFiles(
|
|||||||
'rtems/machine/rtems-bsd-select.h',
|
'rtems/machine/rtems-bsd-select.h',
|
||||||
'rtems/machine/rtems-bsd-taskqueue.h',
|
'rtems/machine/rtems-bsd-taskqueue.h',
|
||||||
'rtems/machine/rtems-bsd-bus-dma.h',
|
'rtems/machine/rtems-bsd-bus-dma.h',
|
||||||
|
'rtems/machine/rtems-bsd-bus-devicet.h',
|
||||||
'bsd.h',
|
'bsd.h',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
73
rtemsbsd/freebsd/machine/rtems-bsd-devicet.h
Normal file
73
rtemsbsd/freebsd/machine/rtems-bsd-devicet.h
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
*
|
||||||
|
* @ingroup rtems_bsd_rtems
|
||||||
|
*
|
||||||
|
* @brief This file describes the divice structure. It was derived
|
||||||
|
* from the libbsdport source.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* COPYRIGHT (c) 2012. On-Line Applications Research Corporation (OAR).
|
||||||
|
* 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _RTEMS_BSD_MACHINE_RTEMS_BSD_DEVICET_H_
|
||||||
|
#define _RTEMS_BSD_MACHINE_RTEMS_BSD_DEVICET_H_
|
||||||
|
|
||||||
|
#include <rtems.h>
|
||||||
|
#include <rtems/bspIo.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <freebsd/sys/queue.h>
|
||||||
|
|
||||||
|
typedef struct device *device_t;
|
||||||
|
|
||||||
|
typedef struct _pcidev_t {
|
||||||
|
unsigned short bus;
|
||||||
|
unsigned char dev;
|
||||||
|
unsigned char fun;
|
||||||
|
} pcidev_t;
|
||||||
|
|
||||||
|
#define DEVICE_SOFTC_ALIGNMENT 16
|
||||||
|
|
||||||
|
struct device {
|
||||||
|
union {
|
||||||
|
pcidev_t pci;
|
||||||
|
} bushdr;
|
||||||
|
int type;
|
||||||
|
STAILQ_ENTRY(device) list;
|
||||||
|
const char *name;
|
||||||
|
char nameunit[16]; /* NEVER use knowledge about the size of this -- we may change it */
|
||||||
|
int unit;
|
||||||
|
char *desc;
|
||||||
|
driver_t *drv;
|
||||||
|
int attached;
|
||||||
|
void *rawmem; /* back pointer */
|
||||||
|
struct rtems_bsdnet_ifconfig *ifconfig;
|
||||||
|
char softc[] __attribute__ ((aligned(DEVICE_SOFTC_ALIGNMENT), may_alias));
|
||||||
|
/* a pointer to back to the device is installed past the 'softc' */
|
||||||
|
};
|
||||||
|
#endif
|
@@ -49,6 +49,11 @@
|
|||||||
#include <freebsd/sys/rman.h>
|
#include <freebsd/sys/rman.h>
|
||||||
#include <freebsd/sys/malloc.h>
|
#include <freebsd/sys/malloc.h>
|
||||||
|
|
||||||
|
#include <bsp.h>
|
||||||
|
#include <freebsd/machine/rtems-bsd-devicet.h>
|
||||||
|
#include <bsp/irq.h>
|
||||||
|
#include <rtems/irq.h>
|
||||||
|
|
||||||
#if defined(__i386__)
|
#if defined(__i386__)
|
||||||
#include <freebsd/machine/rtems-bsd-config.h>
|
#include <freebsd/machine/rtems-bsd-config.h>
|
||||||
#define I386_BUS_SPACE_MEM 0 /* space is mem space */
|
#define I386_BUS_SPACE_MEM 0 /* space is mem space */
|
||||||
@@ -108,11 +113,8 @@ nexus_init_resources(void)
|
|||||||
* resource manager.
|
* resource manager.
|
||||||
*/
|
*/
|
||||||
for (irq = 0; irq < NUM_IO_INTS; irq++)
|
for (irq = 0; irq < NUM_IO_INTS; irq++)
|
||||||
#ifndef __rtems__
|
if (rman_manage_region(&irq_rman, irq, irq) != 0)
|
||||||
if (intr_lookup_source(irq) != NULL)
|
panic("nexus_init_resources irq_rmand");
|
||||||
#endif
|
|
||||||
if (rman_manage_region(&irq_rman, irq, irq) != 0)
|
|
||||||
panic("nexus_init_resources irq_rmand");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ISA DMA on PCI systems is implemented in the ISA part of each
|
* ISA DMA on PCI systems is implemented in the ISA part of each
|
||||||
@@ -241,22 +243,18 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SYS_RES_IRQ:
|
case SYS_RES_IRQ:
|
||||||
printf( "nexus_alloc_resource: IRQ\n" );
|
|
||||||
rm = &irq_rman;
|
rm = &irq_rman;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SYS_RES_DRQ:
|
case SYS_RES_DRQ:
|
||||||
printf( "nexus_alloc_resource: DRQ\n" );
|
|
||||||
rm = &drq_rman;
|
rm = &drq_rman;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SYS_RES_IOPORT:
|
case SYS_RES_IOPORT:
|
||||||
printf( "nexus_alloc_resource: IO\n" );
|
|
||||||
rm = &port_rman;
|
rm = &port_rman;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SYS_RES_MEMORY:
|
case SYS_RES_MEMORY:
|
||||||
printf( "nexus_alloc_resource: Memory\n" );
|
|
||||||
rm = &mem_rman;
|
rm = &mem_rman;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -265,14 +263,12 @@ printf( "nexus_alloc_resource: Memory\n" );
|
|||||||
}
|
}
|
||||||
|
|
||||||
rv = rman_reserve_resource(rm, start, end, count, flags, child);
|
rv = rman_reserve_resource(rm, start, end, count, flags, child);
|
||||||
printf( "nexus_alloc_resource: rman_reserve_resource ==> %d\n", rv );
|
|
||||||
if (rv == 0)
|
if (rv == 0)
|
||||||
return 0;
|
return 0;
|
||||||
rman_set_rid(rv, *rid);
|
rman_set_rid(rv, *rid);
|
||||||
|
|
||||||
if (needactivate) {
|
if (needactivate) {
|
||||||
if (bus_activate_resource(child, type, *rid, rv)) {
|
if (bus_activate_resource(child, type, *rid, rv)) {
|
||||||
printf( "nexus_alloc_resource: bus_activate_resource failed\n", rv );
|
|
||||||
rman_release_resource(rv);
|
rman_release_resource(rv);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -355,6 +351,59 @@ nexus_release_resource(device_t bus, device_t child, int type, int rid,
|
|||||||
return (rman_release_resource(r));
|
return (rman_release_resource(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void noop(const rtems_irq_connect_data *unused) {};
|
||||||
|
static int noop1(const rtems_irq_connect_data *unused) { return 0;};
|
||||||
|
|
||||||
|
static int
|
||||||
|
bspExtInstallSharedISR(int irqLine, void (*isr)(void *), void * uarg, int flags)
|
||||||
|
{
|
||||||
|
return rtems_interrupt_handler_install(
|
||||||
|
irqLine,
|
||||||
|
"BSD Interrupt",
|
||||||
|
RTEMS_INTERRUPT_SHARED,
|
||||||
|
isr,
|
||||||
|
uarg
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
intr_add_handler(const char *name, int vector, driver_filter_t filter,
|
||||||
|
driver_intr_t handler, void *arg, enum intr_type flags, void **cookiep)
|
||||||
|
{
|
||||||
|
int rval;
|
||||||
|
|
||||||
|
rval = bspExtInstallSharedISR(vector, handler, arg, 0);
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
nexus_setup_intr(device_t bus, device_t child, struct resource *irq,
|
||||||
|
int flags, driver_filter_t filter, void (*ihand)(void *),
|
||||||
|
void *arg, void **cookiep)
|
||||||
|
{
|
||||||
|
int error;
|
||||||
|
|
||||||
|
/* somebody tried to setup an irq that failed to allocate! */
|
||||||
|
if (irq == NULL)
|
||||||
|
panic("nexus_setup_intr: NULL irq resource!");
|
||||||
|
|
||||||
|
*cookiep = 0;
|
||||||
|
if ((rman_get_flags(irq) & RF_SHAREABLE) == 0)
|
||||||
|
flags |= INTR_EXCL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We depend here on rman_activate_resource() being idempotent.
|
||||||
|
*/
|
||||||
|
error = rman_activate_resource(irq);
|
||||||
|
if (error)
|
||||||
|
return (error);
|
||||||
|
|
||||||
|
error = intr_add_handler(device_get_nameunit(child),
|
||||||
|
rman_get_start(irq), filter, ihand, arg, flags, cookiep);
|
||||||
|
|
||||||
|
return (error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static device_method_t nexus_methods [] = {
|
static device_method_t nexus_methods [] = {
|
||||||
/* Device interface */
|
/* Device interface */
|
||||||
@@ -372,6 +421,7 @@ static device_method_t nexus_methods [] = {
|
|||||||
DEVMETHOD(bus_release_resource, nexus_release_resource),
|
DEVMETHOD(bus_release_resource, nexus_release_resource),
|
||||||
DEVMETHOD(bus_activate_resource, nexus_activate_resource),
|
DEVMETHOD(bus_activate_resource, nexus_activate_resource),
|
||||||
DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource),
|
DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource),
|
||||||
|
DEVMETHOD(bus_setup_intr, nexus_setup_intr),
|
||||||
|
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user