本文整理汇总了C++中rman_get_bustag函数的典型用法代码示例。如果您正苦于以下问题:C++ rman_get_bustag函数的具体用法?C++ rman_get_bustag怎么用?C++ rman_get_bustag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rman_get_bustag函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: cs4281_pci_attach
static int
cs4281_pci_attach(device_t dev)
{
struct sc_info *sc;
struct ac97_info *codec = NULL;
char status[SND_STATUSLEN];
sc = kmalloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO);
sc->dev = dev;
sc->type = pci_get_devid(dev);
pci_enable_busmaster(dev);
if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
/* Reset the power state. */
device_printf(dev, "chip is in D%d power mode "
"-- setting to D0\n", pci_get_powerstate(dev));
pci_set_powerstate(dev, PCI_POWERSTATE_D0);
}
sc->regid = PCIR_BAR(0);
sc->regtype = SYS_RES_MEMORY;
sc->reg = bus_alloc_resource(dev, sc->regtype, &sc->regid,
0, ~0, CS4281PCI_BA0_SIZE, RF_ACTIVE);
if (!sc->reg) {
sc->regtype = SYS_RES_IOPORT;
sc->reg = bus_alloc_resource(dev, sc->regtype, &sc->regid,
0, ~0, CS4281PCI_BA0_SIZE, RF_ACTIVE);
if (!sc->reg) {
device_printf(dev, "unable to allocate register space\n");
goto bad;
}
}
sc->st = rman_get_bustag(sc->reg);
sc->sh = rman_get_bushandle(sc->reg);
sc->memid = PCIR_BAR(1);
sc->mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->memid, 0,
~0, CS4281PCI_BA1_SIZE, RF_ACTIVE);
if (sc->mem == NULL) {
device_printf(dev, "unable to allocate fifo space\n");
goto bad;
}
sc->irqid = 0;
sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irqid,
RF_ACTIVE | RF_SHAREABLE);
if (!sc->irq) {
device_printf(dev, "unable to allocate interrupt\n");
goto bad;
}
if (snd_setup_intr(dev, sc->irq, 0, cs4281_intr, sc, &sc->ih)) {
device_printf(dev, "unable to setup interrupt\n");
goto bad;
}
sc->bufsz = pcm_getbuffersize(dev, 4096, CS4281_DEFAULT_BUFSZ, 65536);
if (bus_dma_tag_create(/*parent*/bus_get_dma_tag(dev), /*alignment*/2,
/*boundary*/0,
/*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
/*highaddr*/BUS_SPACE_MAXADDR,
/*filter*/NULL, /*filterarg*/NULL,
/*maxsize*/sc->bufsz, /*nsegments*/1,
/*maxsegz*/0x3ffff,
/*flags*/0,
&sc->parent_dmat) != 0) {
device_printf(dev, "unable to create dma tag\n");
goto bad;
}
/* power up */
cs4281_power(sc, 0);
/* init chip */
if (cs4281_init(sc) == -1) {
device_printf(dev, "unable to initialize the card\n");
goto bad;
}
/* create/init mixer */
codec = AC97_CREATE(dev, sc, cs4281_ac97);
if (codec == NULL)
goto bad;
mixer_init(dev, ac97_getmixerclass(), codec);
if (pcm_register(dev, sc, 1, 1))
goto bad;
pcm_addchan(dev, PCMDIR_PLAY, &cs4281chan_class, sc);
pcm_addchan(dev, PCMDIR_REC, &cs4281chan_class, sc);
ksnprintf(status, SND_STATUSLEN, "at %s 0x%lx irq %ld %s",
(sc->regtype == SYS_RES_IOPORT)? "io" : "memory",
rman_get_start(sc->reg), rman_get_start(sc->irq),PCM_KLDSTRING(snd_cs4281));
pcm_setstatus(dev, status);
//.........这里部分代码省略.........
开发者ID:kusumi,项目名称:DragonFlyBSD,代码行数:101,代码来源:cs4281.c
示例2: dotg_obio_attach
static int
dotg_obio_attach(device_t dev)
{
struct dwc_otg_softc *sc = device_get_softc(dev);
uint32_t tmp;
int err, rid;
/* setup controller interface softc */
/* initialise some bus fields */
sc->sc_mode = DWC_MODE_HOST;
sc->sc_bus.parent = dev;
sc->sc_bus.devices = sc->sc_devices;
sc->sc_bus.devices_max = DWC_OTG_MAX_DEVICES;
sc->sc_bus.dma_bits = 32;
/* get all DMA memory */
if (usb_bus_mem_alloc_all(&sc->sc_bus,
USB_GET_DMA_TAG(dev), NULL)) {
printf("No mem\n");
return (ENOMEM);
}
rid = 0;
sc->sc_io_res =
bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
if (!(sc->sc_io_res)) {
printf("Can`t alloc MEM\n");
goto error;
}
sc->sc_io_tag = rman_get_bustag(sc->sc_io_res);
sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res);
sc->sc_io_size = rman_get_size(sc->sc_io_res);
rid = 0;
sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
&rid, RF_ACTIVE);
if (!(sc->sc_irq_res)) {
printf("Can`t alloc IRQ\n");
goto error;
}
sc->sc_bus.bdev = device_add_child(dev, "usbus", -1);
if (!(sc->sc_bus.bdev)) {
printf("Can`t add usbus\n");
goto error;
}
device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
#if (__FreeBSD_version >= 700031)
err = bus_setup_intr(dev, sc->sc_irq_res,
INTR_TYPE_TTY | INTR_MPSAFE, dwc_otg_filter_interrupt,
dwc_otg_interrupt, sc, &sc->sc_intr_hdl);
#else
#error error
err = bus_setup_intr(dev, sc->sc_irq_res,
INTR_TYPE_BIO | INTR_MPSAFE,(driver_intr_t*)dwc_otg_interrupt,
sc, &sc->sc_intr_hdl);
#endif
if (err) {
sc->sc_intr_hdl = NULL;
printf("Can`t set IRQ handle\n");
goto error;
}
/* Run clock for OTG core */
rt305x_sysctl_set(SYSCTL_CLKCFG1, rt305x_sysctl_get(SYSCTL_CLKCFG1) |
SYSCTL_CLKCFG1_OTG_CLK_EN);
tmp = rt305x_sysctl_get(SYSCTL_RSTCTRL);
rt305x_sysctl_set(SYSCTL_RSTCTRL, tmp | SYSCTL_RSTCTRL_OTG);
DELAY(100);
/*
* Docs say that RSTCTRL bits for RT305x are W1C, so there should
* be no need for the below, but who really knows?
*/
// rt305x_sysctl_set(SYSCTL_RSTCTRL, tmp & ~SYSCTL_RSTCTRL_OTG);
// DELAY(100);
err = dwc_otg_init(sc);
if (err) printf("dotg_init fail\n");
if (!err) {
err = device_probe_and_attach(sc->sc_bus.bdev);
if (err) printf("device_probe_and_attach fail %d\n", err);
}
if (err) {
goto error;
}
return (0);
error:
dotg_obio_detach(dev);
return (ENXIO);
}
开发者ID:2trill2spill,项目名称:freebsd,代码行数:92,代码来源:rt305x_dotg.c
示例3: ahc_isa_attach
static int
ahc_isa_attach(device_t dev)
{
struct aic7770_identity *entry;
bus_space_tag_t tag;
bus_space_handle_t bsh;
struct resource *regs;
struct ahc_softc *ahc;
char *name;
int zero;
int error;
zero = 0;
regs = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &zero, RF_ACTIVE);
if (regs == NULL)
return (ENOMEM);
tag = rman_get_bustag(regs);
bsh = rman_get_bushandle(regs);
entry = ahc_isa_find_device(tag, bsh);
bus_release_resource(dev, SYS_RES_IOPORT, zero, regs);
if (entry == NULL)
return (ENODEV);
/*
* Allocate a softc for this card and
* set it up for attachment by our
* common detect routine.
*/
name = malloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_NOWAIT);
if (name == NULL)
return (ENOMEM);
strcpy(name, device_get_nameunit(dev));
ahc = ahc_alloc(dev, name);
if (ahc == NULL)
return (ENOMEM);
ahc_set_unit(ahc, device_get_unit(dev));
/* Allocate a dmatag for our SCB DMA maps */
error = aic_dma_tag_create(ahc, /*parent*/bus_get_dma_tag(dev),
/*alignment*/1, /*boundary*/0,
/*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
/*highaddr*/BUS_SPACE_MAXADDR,
/*filter*/NULL, /*filterarg*/NULL,
/*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
/*nsegments*/AHC_NSEG,
/*maxsegsz*/AHC_MAXTRANSFER_SIZE,
/*flags*/0,
&ahc->parent_dmat);
if (error != 0) {
printf("ahc_isa_attach: Could not allocate DMA tag "
"- error %d\n", error);
ahc_free(ahc);
return (ENOMEM);
}
ahc->dev_softc = dev;
error = aic7770_config(ahc, entry, /*unused ioport arg*/0);
if (error != 0) {
ahc_free(ahc);
return (error);
}
ahc_attach(ahc);
return (0);
}
开发者ID:ele7enxxh,项目名称:dtrace-pf,代码行数:67,代码来源:ahc_isa.c
示例4: xhci_pci_attach
static int
xhci_pci_attach(device_t self)
{
struct xhci_softc *sc = device_get_softc(self);
int count, err, rid;
uint8_t usedma32;
rid = PCI_XHCI_CBMEM;
sc->sc_io_res = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid,
RF_ACTIVE);
if (!sc->sc_io_res) {
device_printf(self, "Could not map memory\n");
return (ENOMEM);
}
sc->sc_io_tag = rman_get_bustag(sc->sc_io_res);
sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res);
sc->sc_io_size = rman_get_size(sc->sc_io_res);
switch (pci_get_devid(self)) {
case 0x01941033: /* NEC uPD720200 USB 3.0 controller */
/* Don't use 64-bit DMA on these controllers. */
usedma32 = 1;
break;
case 0x0f358086: /* BayTrail */
case 0x9c318086: /* Panther Point */
case 0x1e318086: /* Panther Point */
case 0x8c318086: /* Lynx Point */
case 0x8cb18086: /* Wildcat Point */
/*
* On Intel chipsets, reroute ports from EHCI to XHCI
* controller and use a different IMOD value.
*/
sc->sc_port_route = &xhci_pci_port_route;
sc->sc_imod_default = XHCI_IMOD_DEFAULT_LP;
/* FALLTHROUGH */
default:
usedma32 = 0;
break;
}
if (xhci_init(sc, self, usedma32)) {
device_printf(self, "Could not initialize softc\n");
bus_release_resource(self, SYS_RES_MEMORY, PCI_XHCI_CBMEM,
sc->sc_io_res);
return (ENXIO);
}
pci_enable_busmaster(self);
usb_callout_init_mtx(&sc->sc_callout, &sc->sc_bus.bus_mtx, 0);
rid = 0;
if (xhci_use_msi) {
count = 1;
if (pci_alloc_msi(self, &count) == 0) {
if (bootverbose)
device_printf(self, "MSI enabled\n");
rid = 1;
}
}
sc->sc_irq_res = bus_alloc_resource_any(self, SYS_RES_IRQ, &rid,
RF_ACTIVE | (rid != 0 ? 0 : RF_SHAREABLE));
if (sc->sc_irq_res == NULL) {
pci_release_msi(self);
device_printf(self, "Could not allocate IRQ\n");
/* goto error; FALLTHROUGH - use polling */
}
sc->sc_bus.bdev = device_add_child(self, "usbus", -1);
if (sc->sc_bus.bdev == NULL) {
device_printf(self, "Could not add USB device\n");
goto error;
}
device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
sprintf(sc->sc_vendor, "0x%04x", pci_get_vendor(self));
if (sc->sc_irq_res != NULL) {
err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
NULL, (driver_intr_t *)xhci_interrupt, sc, &sc->sc_intr_hdl);
if (err != 0) {
bus_release_resource(self, SYS_RES_IRQ,
rman_get_rid(sc->sc_irq_res), sc->sc_irq_res);
sc->sc_irq_res = NULL;
pci_release_msi(self);
device_printf(self, "Could not setup IRQ, err=%d\n", err);
sc->sc_intr_hdl = NULL;
}
}
if (sc->sc_irq_res == NULL || sc->sc_intr_hdl == NULL) {
if (xhci_use_polling() != 0) {
device_printf(self, "Interrupt polling at %dHz\n", hz);
USB_BUS_LOCK(&sc->sc_bus);
xhci_interrupt_poll(sc);
USB_BUS_UNLOCK(&sc->sc_bus);
} else
goto error;
}
xhci_pci_take_controller(self);
//.........这里部分代码省略.........
开发者ID:ralphost,项目名称:NextBSD,代码行数:101,代码来源:xhci_pci.c
示例5: ral_pci_attach
static int
ral_pci_attach(device_t dev)
{
struct ral_pci_softc *psc = device_get_softc(dev);
struct rt2560_softc *sc = &psc->u.sc_rt2560;
int count, error, rid;
pci_enable_busmaster(dev);
switch (pci_get_device(dev)) {
case 0x0201:
psc->sc_opns = &ral_rt2560_opns;
break;
case 0x0301:
case 0x0302:
case 0x0401:
psc->sc_opns = &ral_rt2661_opns;
break;
default:
psc->sc_opns = &ral_rt2860_opns;
break;
}
rid = PCIR_BAR(0);
psc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
RF_ACTIVE);
if (psc->mem == NULL) {
device_printf(dev, "could not allocate memory resource\n");
return ENXIO;
}
sc->sc_st = rman_get_bustag(psc->mem);
sc->sc_sh = rman_get_bushandle(psc->mem);
sc->sc_invalid = 1;
rid = 0;
if (ral_msi_disable == 0) {
count = 1;
if (pci_alloc_msi(dev, &count) == 0)
rid = 1;
}
psc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE |
(rid != 0 ? 0 : RF_SHAREABLE));
if (psc->irq == NULL) {
device_printf(dev, "could not allocate interrupt resource\n");
pci_release_msi(dev);
bus_release_resource(dev, SYS_RES_MEMORY,
rman_get_rid(psc->mem), psc->mem);
return ENXIO;
}
error = (*psc->sc_opns->attach)(dev, pci_get_device(dev));
if (error != 0) {
(void)ral_pci_detach(dev);
return error;
}
/*
* Hook our interrupt after all initialization is complete.
*/
error = bus_setup_intr(dev, psc->irq, INTR_TYPE_NET | INTR_MPSAFE,
NULL, psc->sc_opns->intr, psc, &psc->sc_ih);
if (error != 0) {
device_printf(dev, "could not set up interrupt\n");
(void)ral_pci_detach(dev);
return error;
}
sc->sc_invalid = 0;
return 0;
}
开发者ID:JabirTech,项目名称:Source,代码行数:71,代码来源:if_ral_pci.c
示例6: acpi_ec_attach
static int
acpi_ec_attach(device_t dev)
{
struct acpi_ec_softc *sc;
struct acpi_ec_params *params;
ACPI_STATUS Status;
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
/* Fetch/initialize softc (assumes softc is pre-zeroed). */
sc = device_get_softc(dev);
params = acpi_get_private(dev);
sc->ec_dev = dev;
sc->ec_handle = acpi_get_handle(dev);
/* Retrieve previously probed values via device ivars. */
sc->ec_glk = params->glk;
sc->ec_gpebit = params->gpe_bit;
sc->ec_gpehandle = params->gpe_handle;
sc->ec_uid = params->uid;
sc->ec_suspending = FALSE;
acpi_set_private(dev, NULL);
free(params, M_TEMP);
/* Attach bus resources for data and command/status ports. */
sc->ec_data_rid = 0;
sc->ec_data_res = bus_alloc_resource_any(sc->ec_dev, SYS_RES_IOPORT,
&sc->ec_data_rid, RF_ACTIVE);
if (sc->ec_data_res == NULL) {
device_printf(dev, "can't allocate data port\n");
goto error;
}
sc->ec_data_tag = rman_get_bustag(sc->ec_data_res);
sc->ec_data_handle = rman_get_bushandle(sc->ec_data_res);
sc->ec_csr_rid = 1;
sc->ec_csr_res = bus_alloc_resource_any(sc->ec_dev, SYS_RES_IOPORT,
&sc->ec_csr_rid, RF_ACTIVE);
if (sc->ec_csr_res == NULL) {
device_printf(dev, "can't allocate command/status port\n");
goto error;
}
sc->ec_csr_tag = rman_get_bustag(sc->ec_csr_res);
sc->ec_csr_handle = rman_get_bushandle(sc->ec_csr_res);
/*
* Install a handler for this EC's GPE bit. We want edge-triggered
* behavior.
*/
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attaching GPE handler\n"));
Status = AcpiInstallGpeHandler(sc->ec_gpehandle, sc->ec_gpebit,
ACPI_GPE_EDGE_TRIGGERED, &EcGpeHandler, sc);
if (ACPI_FAILURE(Status)) {
device_printf(dev, "can't install GPE handler for %s - %s\n",
acpi_name(sc->ec_handle), AcpiFormatException(Status));
goto error;
}
/*
* Install address space handler
*/
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attaching address space handler\n"));
Status = AcpiInstallAddressSpaceHandler(sc->ec_handle, ACPI_ADR_SPACE_EC,
&EcSpaceHandler, &EcSpaceSetup, sc);
if (ACPI_FAILURE(Status)) {
device_printf(dev, "can't install address space handler for %s - %s\n",
acpi_name(sc->ec_handle), AcpiFormatException(Status));
goto error;
}
/* Enable runtime GPEs for the handler. */
Status = AcpiSetGpeType(sc->ec_gpehandle, sc->ec_gpebit,
ACPI_GPE_TYPE_RUNTIME);
if (ACPI_FAILURE(Status)) {
device_printf(dev, "AcpiSetGpeType failed: %s\n",
AcpiFormatException(Status));
goto error;
}
Status = AcpiEnableGpe(sc->ec_gpehandle, sc->ec_gpebit, ACPI_NOT_ISR);
if (ACPI_FAILURE(Status)) {
device_printf(dev, "AcpiEnableGpe failed: %s\n",
AcpiFormatException(Status));
goto error;
}
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "acpi_ec_attach complete\n"));
return (0);
error:
AcpiRemoveGpeHandler(sc->ec_gpehandle, sc->ec_gpebit, &EcGpeHandler);
AcpiRemoveAddressSpaceHandler(sc->ec_handle, ACPI_ADR_SPACE_EC,
EcSpaceHandler);
if (sc->ec_csr_res)
bus_release_resource(sc->ec_dev, SYS_RES_IOPORT, sc->ec_csr_rid,
sc->ec_csr_res);
if (sc->ec_data_res)
bus_release_resource(sc->ec_dev, SYS_RES_IOPORT, sc->ec_data_rid,
sc->ec_data_res);
return (ENXIO);
}
开发者ID:oza,项目名称:FreeBSD-7.3-dyntick,代码行数:100,代码来源:acpi_ec.c
示例7: iir_pci_attach
static int
iir_pci_attach(device_t dev)
{
struct gdt_softc *gdt;
struct resource *io = NULL, *irq = NULL;
int retries, rid, error = 0;
void *ih;
u_int8_t protocol;
/* map DPMEM */
rid = PCI_DPMEM;
io = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
if (io == NULL) {
device_printf(dev, "can't allocate register resources\n");
error = ENOMEM;
goto err;
}
/* get IRQ */
rid = 0;
irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
RF_ACTIVE | RF_SHAREABLE);
if (irq == NULL) {
device_printf(dev, "can't find IRQ value\n");
error = ENOMEM;
goto err;
}
gdt = device_get_softc(dev);
gdt->sc_devnode = dev;
gdt->sc_init_level = 0;
gdt->sc_dpmemt = rman_get_bustag(io);
gdt->sc_dpmemh = rman_get_bushandle(io);
gdt->sc_dpmembase = rman_get_start(io);
gdt->sc_hanum = device_get_unit(dev);
gdt->sc_bus = pci_get_bus(dev);
gdt->sc_slot = pci_get_slot(dev);
gdt->sc_vendor = pci_get_vendor(dev);
gdt->sc_device = pci_get_device(dev);
gdt->sc_subdevice = pci_get_subdevice(dev);
gdt->sc_class = GDT_MPR;
/* no FC ctr.
if (gdt->sc_device >= GDT_PCI_PRODUCT_FC)
gdt->sc_class |= GDT_FC;
*/
/* initialize RP controller */
/* check and reset interface area */
bus_space_write_4(gdt->sc_dpmemt, gdt->sc_dpmemh, GDT_MPR_IC,
htole32(GDT_MPR_MAGIC));
if (bus_space_read_4(gdt->sc_dpmemt, gdt->sc_dpmemh, GDT_MPR_IC) !=
htole32(GDT_MPR_MAGIC)) {
printf("cannot access DPMEM at 0x%jx (shadowed?)\n",
(uintmax_t)gdt->sc_dpmembase);
error = ENXIO;
goto err;
}
bus_space_set_region_4(gdt->sc_dpmemt, gdt->sc_dpmemh, GDT_I960_SZ, htole32(0),
GDT_MPR_SZ >> 2);
/* Disable everything */
bus_space_write_1(gdt->sc_dpmemt, gdt->sc_dpmemh, GDT_EDOOR_EN,
bus_space_read_1(gdt->sc_dpmemt, gdt->sc_dpmemh,
GDT_EDOOR_EN) | 4);
bus_space_write_1(gdt->sc_dpmemt, gdt->sc_dpmemh, GDT_MPR_EDOOR, 0xff);
bus_space_write_1(gdt->sc_dpmemt, gdt->sc_dpmemh, GDT_MPR_IC + GDT_S_STATUS,
0);
bus_space_write_1(gdt->sc_dpmemt, gdt->sc_dpmemh, GDT_MPR_IC + GDT_CMD_INDEX,
0);
bus_space_write_4(gdt->sc_dpmemt, gdt->sc_dpmemh, GDT_MPR_IC + GDT_S_INFO,
htole32(gdt->sc_dpmembase));
bus_space_write_1(gdt->sc_dpmemt, gdt->sc_dpmemh, GDT_MPR_IC + GDT_S_CMD_INDX,
0xff);
bus_space_write_1(gdt->sc_dpmemt, gdt->sc_dpmemh, GDT_MPR_LDOOR, 1);
DELAY(20);
retries = GDT_RETRIES;
while (bus_space_read_1(gdt->sc_dpmemt, gdt->sc_dpmemh,
GDT_MPR_IC + GDT_S_STATUS) != 0xff) {
if (--retries == 0) {
printf("DEINIT failed\n");
error = ENXIO;
goto err;
}
DELAY(1);
}
protocol = (uint8_t)le32toh(bus_space_read_4(gdt->sc_dpmemt, gdt->sc_dpmemh,
GDT_MPR_IC + GDT_S_INFO));
bus_space_write_1(gdt->sc_dpmemt, gdt->sc_dpmemh, GDT_MPR_IC + GDT_S_STATUS,
0);
if (protocol != GDT_PROTOCOL_VERSION) {
printf("unsupported protocol %d\n", protocol);
error = ENXIO;
goto err;
}
/* special commnd to controller BIOS */
bus_space_write_4(gdt->sc_dpmemt, gdt->sc_dpmemh, GDT_MPR_IC + GDT_S_INFO,
//.........这里部分代码省略.........
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:101,代码来源:iir_pci.c
示例8: aac_pci_attach
/*
* Allocate resources for our device, set up the bus interface.
*/
static int
aac_pci_attach(device_t dev)
{
struct aac_softc *sc;
const struct aac_ident *id;
int count, error, reg, rid;
fwprintf(NULL, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
/*
* Initialise softc.
*/
sc = device_get_softc(dev);
sc->aac_dev = dev;
/* assume failure is 'not configured' */
error = ENXIO;
/*
* Verify that the adapter is correctly set up in PCI space.
*/
pci_enable_busmaster(dev);
if (!(pci_read_config(dev, PCIR_COMMAND, 2) & PCIM_CMD_BUSMASTEREN)) {
device_printf(dev, "can't enable bus-master feature\n");
goto out;
}
/*
* Allocate the PCI register window(s).
*/
rid = PCIR_BAR(0);
if ((sc->aac_regs_res0 = bus_alloc_resource_any(dev,
SYS_RES_MEMORY, &rid, RF_ACTIVE)) == NULL) {
device_printf(dev, "can't allocate register window 0\n");
goto out;
}
sc->aac_btag0 = rman_get_bustag(sc->aac_regs_res0);
sc->aac_bhandle0 = rman_get_bushandle(sc->aac_regs_res0);
if (sc->aac_hwif == AAC_HWIF_NARK) {
rid = PCIR_BAR(1);
if ((sc->aac_regs_res1 = bus_alloc_resource_any(dev,
SYS_RES_MEMORY, &rid, RF_ACTIVE)) == NULL) {
device_printf(dev,
"can't allocate register window 1\n");
goto out;
}
sc->aac_btag1 = rman_get_bustag(sc->aac_regs_res1);
sc->aac_bhandle1 = rman_get_bushandle(sc->aac_regs_res1);
} else {
sc->aac_regs_res1 = sc->aac_regs_res0;
sc->aac_btag1 = sc->aac_btag0;
sc->aac_bhandle1 = sc->aac_bhandle0;
}
/*
* Allocate the interrupt.
*/
rid = 0;
count = 0;
if (aac_enable_msi != 0 && pci_find_cap(dev, PCIY_MSI, ®) == 0) {
count = pci_msi_count(dev);
if (count > 1)
count = 1;
else
count = 0;
if (count == 1 && pci_alloc_msi(dev, &count) == 0)
rid = 1;
}
if ((sc->aac_irq = bus_alloc_resource_any(sc->aac_dev, SYS_RES_IRQ,
&rid, RF_ACTIVE | (count != 0 ? 0 : RF_SHAREABLE))) == NULL) {
device_printf(dev, "can't allocate interrupt\n");
goto out;
}
/*
* Allocate the parent bus DMA tag appropriate for our PCI interface.
*
* Note that some of these controllers are 64-bit capable.
*/
if (bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */
PAGE_SIZE, 0, /* algnmnt, boundary */
BUS_SPACE_MAXADDR, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filter, filterarg */
BUS_SPACE_MAXSIZE_32BIT, /* maxsize */
BUS_SPACE_UNRESTRICTED, /* nsegments */
BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
0, /* flags */
NULL, NULL, /* No locking needed */
&sc->aac_parent_dmat)) {
device_printf(dev, "can't allocate parent DMA tag\n");
goto out;
}
/*
* Detect the hardware interface version, set up the bus interface
//.........这里部分代码省略.........
开发者ID:ornarium,项目名称:freebsd,代码行数:101,代码来源:aac_pci.c
示例9: pcib_mbus_identify
static void
pcib_mbus_identify(driver_t *driver, device_t parent)
{
const struct obio_pci *info = mv_pci_info;
struct pcib_mbus_softc *sc;
uint32_t control;
while (info->op_base) {
sc = malloc(driver->size, M_DEVBUF, M_NOWAIT | M_ZERO);
if (sc == NULL) {
device_printf(parent, "Could not allocate pcib "
"memory\n");
break;
}
sc->sc_info = info++;
/*
* PCI bridge objects are instantiated immediately. PCI-Express
* bridges require more complicated handling depending on
* platform configuration.
*/
if (sc->sc_info->op_type == MV_TYPE_PCI) {
pcib_mbus_add_child(driver, parent, sc);
continue;
}
/*
* Read link configuration
*/
sc->sc_rid = 0;
sc->sc_res = BUS_ALLOC_RESOURCE(parent, parent, SYS_RES_MEMORY,
&sc->sc_rid, sc->sc_info->op_base, sc->sc_info->op_base +
sc->sc_info->op_size - 1, sc->sc_info->op_size,
RF_ACTIVE);
if (sc->sc_res == NULL) {
device_printf(parent, "Could not map pcib memory\n");
break;
}
sc->sc_bst = rman_get_bustag(sc->sc_res);
sc->sc_bsh = rman_get_bushandle(sc->sc_res);
control = bus_space_read_4(sc->sc_bst, sc->sc_bsh,
PCIE_REG_CONTROL);
BUS_RELEASE_RESOURCE(parent, parent, SYS_RES_MEMORY, sc->sc_rid,
sc->sc_res);
/*
* If this PCI-E port (controller) is configured (by the
* underlying firmware) with lane width other than 1x, there
* are auxiliary resources defined for aggregating more width
* on our lane. Skip all such entries as they are not
* standalone ports and must not have a device object
* instantiated.
*/
if ((control & PCIE_CTRL_LINK1X) == 0)
while (info->op_base &&
info->op_type == MV_TYPE_PCIE_AGGR_LANE)
info++;
pcib_mbus_add_child(driver, parent, sc);
}
}
开发者ID:DangerDexter,项目名称:FreeBSD-8.0-dyntick,代码行数:64,代码来源:mv_pci.c
示例10: acpi_ec_attach
static int
acpi_ec_attach(device_t dev)
{
struct acpi_ec_softc *sc;
ACPI_STATUS Status;
int errval = 0;
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
/*
* Fetch/initialise softc
*/
sc = device_get_softc(dev);
bzero(sc, sizeof(*sc));
sc->ec_dev = dev;
sc->ec_handle = acpi_get_handle(dev);
/*
* Attach bus resources
*/
sc->ec_data_rid = 0;
if ((sc->ec_data_res = bus_alloc_resource(sc->ec_dev, SYS_RES_IOPORT, &sc->ec_data_rid,
0, ~0, 1, RF_ACTIVE)) == NULL) {
device_printf(dev, "can't allocate data port\n");
errval = ENXIO;
goto out;
}
sc->ec_data_tag = rman_get_bustag(sc->ec_data_res);
sc->ec_data_handle = rman_get_bushandle(sc->ec_data_res);
sc->ec_csr_rid = 1;
if ((sc->ec_csr_res = bus_alloc_resource(sc->ec_dev, SYS_RES_IOPORT, &sc->ec_csr_rid,
0, ~0, 1, RF_ACTIVE)) == NULL) {
device_printf(dev, "can't allocate command/status port\n");
errval = ENXIO;
goto out;
}
sc->ec_csr_tag = rman_get_bustag(sc->ec_csr_res);
sc->ec_csr_handle = rman_get_bushandle(sc->ec_csr_res);
/*
* Install GPE handler
*
* Evaluate the _GPE method to find the GPE bit used by the EC to signal
* status (SCI).
*/
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attaching GPE\n"));
if (ACPI_FAILURE(Status = acpi_EvaluateInteger(sc->ec_handle, "_GPE", &sc->ec_gpebit))) {
device_printf(dev, "can't evaluate _GPE - %s\n", AcpiFormatException(Status));
errval =ENXIO;
goto out;
}
/*
* Install a handler for this EC's GPE bit. Note that EC SCIs are
* treated as both edge- and level-triggered interrupts; in other words
* we clear the status bit immediately after getting an EC-SCI, then
* again after we're done processing the event. This guarantees that
* events we cause while performing a transaction (e.g. IBE/OBF) get
* cleared before re-enabling the GPE.
*/
if (ACPI_FAILURE(Status = AcpiInstallGpeHandler(sc->ec_gpebit,
ACPI_EVENT_LEVEL_TRIGGERED |
ACPI_EVENT_EDGE_TRIGGERED,
EcGpeHandler, sc))) {
device_printf(dev, "can't install GPE handler for %s - %s\n",
acpi_name(sc->ec_handle), AcpiFormatException(Status));
errval = ENXIO;
goto out;
}
/*
* Install address space handler
*/
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attaching address space handler\n"));
if (ACPI_FAILURE(Status = AcpiInstallAddressSpaceHandler(sc->ec_handle,
ACPI_ADR_SPACE_EC,
EcSpaceHandler,
EcSpaceSetup,
sc))) {
device_printf(dev, "can't install address space handler for %s - %s\n",
acpi_name(sc->ec_handle), AcpiFormatException(Status));
panic("very suck");
errval = ENXIO;
goto out;
}
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attach complete\n"));
return_VALUE(0);
out:
if(sc->ec_csr_res)
bus_release_resource(sc->ec_dev, SYS_RES_IOPORT, sc->ec_csr_rid,
sc->ec_csr_res);
if(sc->ec_data_res)
bus_release_resource(sc->ec_dev, SYS_RES_IOPORT, sc->ec_data_rid,
sc->ec_data_res);
return_VALUE(errval);
}
开发者ID:UnitedMarsupials,项目名称:kame,代码行数:97,代码来源:acpi_ec.c
示例11: imx_gpt_attach
static int
imx_gpt_attach(device_t dev)
{
struct imx_gpt_softc *sc;
int ctlreg, err;
uint32_t basefreq, prescale;
sc = device_get_softc(dev);
if (bus_alloc_resources(dev, imx_gpt_spec, sc->res)) {
device_printf(dev, "could not allocate resources\n");
return (ENXIO);
}
sc->sc_dev = dev;
sc->sc_iot = rman_get_bustag(sc->res[0]);
sc->sc_ioh = rman_get_bushandle(sc->res[0]);
/*
* For now, just automatically choose a good clock for the hardware
* we're running on. Eventually we could allow selection from the fdt;
* the code in this driver will cope with any clock frequency.
*/
sc->sc_clksrc = GPT_CR_CLKSRC_IPG;
ctlreg = 0;
switch (sc->sc_clksrc) {
case GPT_CR_CLKSRC_32K:
basefreq = 32768;
break;
case GPT_CR_CLKSRC_IPG:
basefreq = imx_ccm_ipg_hz();
break;
case GPT_CR_CLKSRC_IPG_HIGH:
basefreq = imx_ccm_ipg_hz() * 2;
break;
case GPT_CR_CLKSRC_24M:
ctlreg |= GPT_CR_24MEN;
basefreq = 24000000;
break;
case GPT_CR_CLKSRC_NONE:/* Can't run without a clock. */
case GPT_CR_CLKSRC_EXT: /* No way to get the freq of an ext clock. */
default:
device_printf(dev, "Unsupported clock source '%d'\n",
sc->sc_clksrc);
return (EINVAL);
}
/*
* The following setup sequence is from the I.MX6 reference manual,
* "Selecting the clock source". First, disable the clock and
* interrupts. This also clears input and output mode bits and in
* general completes several of the early steps in the procedure.
*/
WRITE4(sc, IMX_GPT_CR, 0);
WRITE4(sc, IMX_GPT_IR, 0);
/* Choose the clock and the power-saving behaviors. */
ctlreg |=
sc->sc_clksrc | /* Use selected clock */
GPT_CR_FRR | /* Just count (FreeRunner mode) */
GPT_CR_STOPEN | /* Run in STOP mode */
GPT_CR_DOZEEN | /* Run in DOZE mode */
GPT_CR_WAITEN | /* Run in WAIT mode */
GPT_CR_DBGEN; /* Run in DEBUG mode */
WRITE4(sc, IMX_GPT_CR, ctlreg);
/*
* The datasheet says to do the software reset after choosing the clock
* source. It says nothing about needing to wait for the reset to
* complete, but the register description does document the fact that
* the reset isn't complete until the SWR bit reads 0, so let's be safe.
* The reset also clears all registers except for a few of the bits in
* CR, but we'll rewrite all the CR bits when we start the counter.
*/
WRITE4(sc, IMX_GPT_CR, ctlreg | GPT_CR_SWR);
while (READ4(sc, IMX_GPT_CR) & GPT_CR_SWR)
continue;
/* Set a prescaler value that gets us near the target frequency. */
if (basefreq < TARGET_FREQUENCY) {
prescale = 0;
sc->clkfreq = basefreq;
} else {
prescale = basefreq / TARGET_FREQUENCY;
sc->clkfreq = basefreq / prescale;
prescale -= 1; /* 1..n range is 0..n-1 in hardware. */
}
WRITE4(sc, IMX_GPT_PR, prescale);
/* Clear the status register. */
WRITE4(sc, IMX_GPT_SR, GPT_IR_ALL);
/* Start the counter. */
WRITE4(sc, IMX_GPT_CR, ctlreg | GPT_CR_EN);
if (bootverbose)
device_printf(dev, "Running on %dKHz clock, base freq %uHz CR=0x%08x, PR=0x%08x\n",
sc->clkfreq / 1000, basefreq, READ4(sc, IMX_GPT_CR), READ4(sc, IMX_GPT_PR));
//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:freebsd,代码行数:101,代码来源:imx_gpt.c
示例12: cbb_pci_attach
static int
cbb_pci_attach(device_t brdev)
{
static int curr_bus_number = 2; /* XXX EVILE BAD (see below) */
struct cbb_softc *sc = (struct cbb_softc *)device_get_softc(brdev);
struct sysctl_ctx_list *sctx;
struct sysctl_oid *soid;
int rid;
device_t parent;
uint32_t pribus;
parent = device_get_parent(brdev);
mtx_init(&sc->mtx, device_get_nameunit(brdev), "cbb", MTX_DEF);
sc->chipset = cbb_chipset(pci_get_devid(brdev), NULL);
sc->dev = brdev;
sc->cbdev = NULL;
sc->exca[0].pccarddev = NULL;
sc->domain = pci_get_domain(brdev);
sc->secbus = pci_read_config(brdev, PCIR_SECBUS_2, 1);
sc->subbus = pci_read_config(brdev, PCIR_SUBBUS_2, 1);
sc->pribus = pcib_get_bus(parent);
SLIST_INIT(&sc->rl);
cbb_powerstate_d0(brdev);
rid = CBBR_SOCKBASE;
sc->base_res = bus_alloc_resource_any(brdev, SYS_RES_MEMORY, &rid,
RF_ACTIVE);
if (!sc->base_res) {
device_printf(brdev, "Could not map register memory\n");
mtx_destroy(&sc->mtx);
return (ENOMEM);
} else {
DEVPRINTF((brdev, "Found memory at %08lx\n",
rman_get_start(sc->base_res)));
}
sc->bst = rman_get_bustag(sc->base_res);
sc->bsh = rman_get_bushandle(sc->base_res);
exca_init(&sc->exca[0], brdev, sc->bst, sc->bsh, CBB_EXCA_OFFSET);
sc->exca[0].flags |= EXCA_HAS_MEMREG_WIN;
sc->exca[0].chipset = EXCA_CARDBUS;
sc->chipinit = cbb_chipinit;
sc->chipinit(sc);
/*Sysctls*/
sctx = device_get_sysctl_ctx(brdev);
soid = device_get_sysctl_tree(brdev);
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "domain",
CTLFLAG_RD, &sc->domain, 0, "Domain number");
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "pribus",
CTLFLAG_RD, &sc->pribus, 0, "Primary bus number");
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "secbus",
CTLFLAG_RD, &sc->secbus, 0, "Secondary bus number");
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "subbus",
CTLFLAG_RD, &sc->subbus, 0, "Subordinate bus number");
#if 0
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "memory",
CTLFLAG_RD, &sc->subbus, 0, "Memory window open");
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "premem",
CTLFLAG_RD, &sc->subbus, 0, "Prefetch memroy window open");
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "io1",
CTLFLAG_RD, &sc->subbus, 0, "io range 1 open");
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "io2",
CTLFLAG_RD, &sc->subbus, 0, "io range 2 open");
#endif
/*
* This is a gross hack. We should be scanning the entire pci
* tree, assigning bus numbers in a way such that we (1) can
* reserve 1 extra bus just in case and (2) all sub busses
* are in an appropriate range.
*/
DEVPRINTF((brdev, "Secondary bus is %d\n", sc->secbus));
pribus = pci_read_config(brdev, PCIR_PRIBUS_2, 1);
if (sc->secbus == 0 || sc->pribus != pribus) {
if (curr_bus_number <= sc->pribus)
curr_bus_number = sc->pribus + 1;
if (pribus != sc->pribus) {
DEVPRINTF((brdev, "Setting primary bus to %d\n",
sc->pribus));
pci_write_config(brdev, PCIR_PRIBUS_2, sc->pribus, 1);
}
sc->secbus = curr_bus_number++;
sc->subbus = curr_bus_number++;
DEVPRINTF((brdev, "Secondary bus set to %d subbus %d\n",
sc->secbus, sc->subbus));
pci_write_config(brdev, PCIR_SECBUS_2, sc->secbus, 1);
pci_write_config(brdev, PCIR_SUBBUS_2, sc->subbus, 1);
}
/* attach children */
sc->cbdev = device_add_child(brdev, "cardbus", -1);
if (sc->cbdev == NULL)
DEVPRINTF((brdev, "WARNING: cannot add cardbus bus.\n"));
else if (device_probe_and_attach(sc->cbdev) != 0)
DEVPRINTF((brdev, "WARNING: cannot attach cardbus bus!\n"));
sc->exca[0].pccarddev = device_add_child(brdev, "pccard", -1);
if (sc->exca[0].pccarddev == NULL)
DEVPRINTF((brdev, "WARNING: cannot add pccard bus.\n"));
//.........这里部分代码省略.........
开发者ID:hlcherub,项目名称:src,代码行数:101,代码来源:pccbb_pci.c
示例13: port_wr
static void
port_wr(struct resource *r, int i, unsigned char v)
{
bus_space_write_1(rman_get_bustag(r), rman_get_bushandle(r), i, v);
}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:5,代码来源:gusc.c
示例14: kr_attach
static int
kr_attach(device_t dev)
{
uint8_t eaddr[ETHER_ADDR_LEN];
struct ifnet *ifp;
struct kr_softc *sc;
int error = 0, rid;
int unit;
sc = device_get_softc(dev);
unit = device_get_unit(dev);
sc->kr_dev = dev;
mtx_init(&sc->kr_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
MTX_DEF);
callout_init_mtx(&sc->kr_stat_callout, &sc->kr_mtx, 0);
TASK_INIT(&sc->kr_link_task, 0, kr_link_task, sc);
pci_enable_busmaster(dev);
/* Map control/status registers. */
sc->kr_rid = 0;
sc->kr_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->kr_rid,
RF_ACTIVE);
if (sc->kr_res == NULL) {
device_printf(dev, "couldn't map memory\n");
error = ENXIO;
goto fail;
}
sc->kr_btag = rman_get_bustag(sc->kr_res);
sc->kr_bhandle = rman_get_bushandle(sc->kr_res);
/* Allocate interrupts */
rid = 0;
sc->kr_rx_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, KR_RX_IRQ,
KR_RX_IRQ, 1, RF_SHAREABLE | RF_ACTIVE);
if (sc->kr_rx_irq == NULL) {
device_printf(dev, "couldn't map rx interrupt\n");
error = ENXIO;
goto fail;
}
rid = 0;
sc->kr_tx_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, KR_TX_IRQ,
KR_TX_IRQ, 1, RF_SHAREABLE | RF_ACTIVE);
if (sc->kr_tx_irq == NULL) {
device_printf(dev, "couldn't map tx interrupt\n");
error = ENXIO;
goto fail;
}
rid = 0;
sc->kr_rx_und_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
KR_RX_UND_IRQ, KR_RX_UND_IRQ, 1, RF_SHAREABLE | RF_ACTIVE);
if (sc->kr_rx_und_irq == NULL) {
device_printf(dev, "couldn't map rx underrun interrupt\n");
error = ENXIO;
goto fail;
}
rid = 0;
sc->kr_tx_ovr_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
KR_TX_OVR_IRQ, KR_TX_OVR_IRQ, 1, RF_SHAREABLE | RF_ACTIVE);
if (sc->kr_tx_ovr_irq == NULL) {
device_printf(dev, "couldn't map tx overrun interrupt\n");
error = ENXIO;
goto fail;
}
/* Allocate ifnet structure. */
ifp = sc->kr_ifp = if_alloc(IFT_ETHER);
if (ifp == NULL) {
device_printf(dev, "couldn't allocate ifnet structure\n");
error = ENOSPC;
goto fail;
}
ifp->if_softc = sc;
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_ioctl = kr_ioctl;
ifp->if_start = kr_start;
ifp->if_init = kr_init;
/* XXX: add real size */
IFQ_SET_MAXLEN(&ifp->if_snd, 9);
ifp->if_snd.ifq_maxlen = 9;
IFQ_SET_READY(&ifp->if_snd);
ifp->if_capenable = ifp->if_capabilities;
eaddr[0] = 0x00;
eaddr[1] = 0x0C;
eaddr[2] = 0x42;
eaddr[3] = 0x09;
//.........这里部分代码省略.........
开发者ID:hmatyschok,项目名称:MeshBSD,代码行数:101,代码来源:if_kr.c
示例15: port_rd
static int
port_rd(struct resource *r, int i)
{
return bus_space_read_1(rman_get_bustag(r), rman_get_bushandle(r), i);
}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:5,代码来源:gusc.c
示例16: fdc_isa_alloc_resources
/*
* On standard ISA, we don't just use an 8 port range
* (e.g. 0x3f0-0x3f7) since that covers an IDE control register at
* 0x3f6. So, on older hardware, we use 0x3f0-0x3f5 and 0x3f7.
* However, some BIOSs omit the control port, while others start at
* 0x3f2. Of the latter, sometimes we have two resources, other times
* we have one. We have to deal with the following cases:
*
* 1: 0x3f0-0x3f5 # very rare
* 2: 0x3f0 # hints -> 0x3f0-0x3f5,0x3f7
* 3: 0x3f0-0x3f5,0x3f7 # Most common
* 4: 0x3f2-0x3f5,0x3f7 # Second most common
* 5: 0x3f2-0x3f5 # implies 0x3f7 too.
* 6: 0x3f2-0x3f3,0x3f4-0x3f5,0x3f7 # becoming common
* 7: 0x3f2-0x3f3,0x3f4-0x3f5 # rare
* 8: 0x3f0-0x3f1,0x3f2-0x3f3,0x3f4-0x3f5,0x3f7
* 9: 0x3f0-0x3f3,0x3f4-0x3f5,0x3f7
*
* The following code is generic for any value of 0x3fx. It is also
* generic for all the above cases, as well as cases where things are
* even weirder.
*/
int
fdc_isa_alloc_resources(device_t dev, struct fdc_data *fdc)
{
struct resource *res;
int i, j, rid, newrid, nport;
u_long port;
fdc->fdc_dev = dev;
rid = 0;
for (i = 0; i < FDC_MAXREG; i++)
fdc->resio[i] = NULL;
nport = isa_get_logicalid(dev) ? 1 : 6;
for (rid = 0; ; rid++) {
newrid = rid;
res = bus_alloc_resource(dev, SYS_RES_IOPORT, &newrid,
0ul, ~0ul, rid == 0 ? nport : 1, RF_ACTIVE);
if (res == NULL)
break;
/*
* Mask off the upper bits of the register, and sanity
* check resource ranges.
*/
i = rman_get_start(res) & 0x7;
if (i + rman_get_size(res) - 1 > FDC_MAXREG) {
bus_release_resource(dev, SYS_RES_IOPORT, newrid, res);
return (ENXIO);
}
for (j = 0; j < rman_get_size(res); j++) {
fdc->resio[i + j] = res;
fdc->ridio[i + j] = newrid;
fdc->ioff[i + j] = j;
fdc->ioh[i + j] = rman_get_bushandle(res);
}
}
if (fdc->resio[2] == NULL) {
device_printf(dev, "No FDOUT register!\n");
return (ENXIO);
}
fdc->iot = rman_get_bustag(fdc->resio[2]);
if (fdc->resio[7] == NULL) {
port = (rman_get_start(fdc->resio[2]) & ~0x7) + 7;
newrid = rid;
res = bus_alloc_resource(dev, SYS_RES_IOPORT, &newrid, port,
port, 1, RF_ACTIVE);
if (res == NULL) {
device_printf(dev, "Faking up FDCTL\n");
fdc->resio[7] = fdc->resio[2];
fdc->ridio[7] = fdc->ridio[2];
fdc->ioff[7] = fdc->ioff[2] + 5;
fdc->ioh[7] = fdc->ioh[2];
} else {
fdc->resio[7] = res;
fdc->ridio[7] = newrid;
fdc->ioff[7] = rman_get_start(res) & 7;
fdc->ioh[7] = rman_get_bushandle(res);
}
}
fdc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &fdc->rid_irq,
RF_ACTIVE | RF_SHAREABLE);
if (fdc->res_irq == NULL) {
device_printf(dev, "cannot reserve interrupt line\n");
return (ENXIO);
}
if ((fdc->flags & FDC_NODMA) == 0) {
fdc->res_drq = bus_alloc_resource_any(dev, SYS_RES_DRQ,
&fdc->rid_drq, RF_ACTIVE | RF_SHAREABLE);
if (fdc->res_drq == NULL) {
device_printf(dev, "cannot reser
|
请发表评论