* compat_open() still needs to get the stack module, as the callout

functionality needs it.
* callout_init_mtx() now initializes the timer manually, since the stack
  might not have been loaded yet (since a device is now attached in
  init_driver()).
* Minor other fixes; the FreeBSD compatibility layer should now be functional
  again.
* Accidently put pci.c into the repository, but that was never meant to happen.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23026 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-11-30 12:28:51 +00:00
parent 053693ef2a
commit 30710739a3
7 changed files with 28 additions and 227 deletions

View File

@ -24,6 +24,5 @@ KernelStaticLibrary libfreebsd_network.a :
mbuf.c
mii.c
mutex.c
pci.c
taskqueue.c
;

View File

@ -1,9 +1,6 @@
/*
* Copyright 2007, Hugo Santos. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Hugo Santos, hugosantos@gmail.com
*/
#include "device.h"
@ -33,7 +30,11 @@ handle_callout(struct net_timer *timer, void *data)
void
callout_init_mtx(struct callout *c, struct mtx *mtx, int flags)
{
gStack->init_timer(&c->c_timer, handle_callout, c);
// we must manually initialize the timer, since the networking
// stack might not be loaded yet
c->c_timer.hook = handle_callout;
c->c_timer.data = c;
c->c_timer.due = 0;
c->c_arg = NULL;
c->c_func = NULL;

View File

@ -279,7 +279,7 @@ device_add_child(device_t parent, const char *name, int unit)
driver_t **driver;
char symbol[128];
snprintf(symbol, sizeof(symbol), "__fbsd_%s%s", name,
snprintf(symbol, sizeof(symbol), "__fbsd_%s_%s", name,
parent->driver->name);
if (get_image_symbol(find_own_image(), symbol, B_SYMBOL_TYPE_DATA,
(void **)&driver) == B_OK)
@ -479,11 +479,11 @@ int resource_int_value(const char *name, int unit, const char *resname,
void *
_kernel_malloc(size_t size, int flags)
{
// our kernel malloc() is insufficent, must handle M_WAIT
// our kernel malloc() is insufficient, must handle M_WAIT
void *ptr = malloc(size);
if (ptr == NULL)
return ptr;
return NULL;
if (flags & M_ZERO)
memset(ptr, 0, size);
@ -518,8 +518,8 @@ _kernel_contigmalloc(const char *file, int line, size_t size, int flags,
if (flags & M_ZERO)
memset(addr, 0, size);
driver_printf("(%s) addr = %p, area = %ld, size = %lu\n",
name, addr, area, size);
//driver_printf("(%s) addr = %p, area = %ld, size = %lu\n",
// name, addr, area, size);
return addr;
}

View File

@ -36,11 +36,16 @@ compat_open(const char *name, uint32 flags, void **cookie)
if (gDeviceNameList[i] == NULL)
return B_ERROR;
if (get_module(NET_STACK_MODULE_NAME, (module_info **)&gStack) != B_OK)
return B_ERROR;
ifp = gDevices[i];
if_printf(ifp, "compat_open(0x%lx)\n", flags);
if (!atomic_test_and_set(&ifp->open_count, 1, 0))
if (atomic_or(&ifp->open_count, 1)) {
put_module(NET_STACK_MODULE_NAME);
return B_BUSY;
}
ifp->if_flags &= ~IFF_UP;
ifp->if_ioctl(ifp, SIOCSIFFLAGS, NULL);
@ -83,6 +88,7 @@ compat_free(void *cookie)
/* TODO: empty out the send queue */
atomic_and(&ifp->open_count, 0);
put_module(NET_STACK_MODULE_NAME);
return B_OK;
}

View File

@ -60,6 +60,7 @@ init_root_device(driver_t *driver, device_t *_root, device_t *_child)
}
root->driver = &sRootDriver;
root->root = root;
child = device_add_child(root, driver->name, 0);
if (child == NULL) {
@ -138,8 +139,8 @@ _fbsd_init_hardware(driver_t *driver)
status_t
_fbsd_init_driver(driver_t *driver)
{
int i, found = 0;
status_t status;
int i = 0;
dprintf("%s: init_driver(%p)\n", gDriverName, driver);
@ -163,8 +164,6 @@ _fbsd_init_driver(driver_t *driver)
goto err3;
}
i = 0;
while (gDeviceCount < MAX_DEVICES) {
device_t root, device;
bool found = false;
@ -180,10 +179,11 @@ _fbsd_init_driver(driver_t *driver)
if (device->methods.probe(device) < 0)
continue;
if (device_attach(device) == 0) {
if (device_attach(device) == 0)
found = true;
break;
}
i++;
break;
}
if (!found) {
@ -192,10 +192,10 @@ _fbsd_init_driver(driver_t *driver)
}
}
if (gDeviceCount > 0) {
TRACE(("%s, ... %d cards.\n", gDriverName, found));
if (gDeviceCount > 0)
return B_OK;
} else if (status == B_OK)
if (status == B_OK)
status = B_ERROR;
if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES))
@ -217,7 +217,7 @@ _fbsd_uninit_driver(driver_t *driver)
TRACE(("%s: uninit_driver(%p)\n", gDriverName, driver));
for (i = 0; gDeviceNameList[i] != NULL; i++) {
for (i = 0; i < gDeviceCount; i++) {
device_delete_child(NULL, gDevices[i]->root_device);
}

View File

@ -48,6 +48,7 @@ if_alloc(u_char type)
}
ifp->link_state_sem = -1;
ifp->open_count = 0;
ifp->flags = 0;
ifq_init(&ifp->receive_queue, semName);

View File

@ -1,206 +0,0 @@
/*
* Copyright 2007, Hugo Santos, hugosantos@gmail.com. All Rights Reserved.
* Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All Rights Reserved.
* Copyright 2004, Marcus Overhagen. All Rights Reserved.
*
* Distributed under the terms of the MIT License.
*/
#include "device.h"
#include <stdio.h>
#include <KernelExport.h>
#include <image.h>
#include <compat/machine/resource.h>
#include <compat/dev/pci/pcireg.h>
#include <compat/dev/pci/pcivar.h>
#include <compat/sys/bus.h>
#include <compat/dev/mii/miivar.h>
//#define DEBUG_PCI
#ifdef DEBUG_PCI
# define TRACE_PCI(dev, format, args...) device_printf(dev, format , ##args)
#else
# define TRACE_PCI(dev, format, args...) do { } while (0)
#endif
uint32_t
pci_read_config(device_t dev, int offset, int size)
{
pci_info *info = &((struct root_device_softc *)dev->root->softc)->pci_info;
uint32_t value = gPci->read_pci_config(info->bus, info->device,
info->function, offset, size);
TRACE_PCI(dev, "pci_read_config(%i, %i) = 0x%x\n", offset, size, value);
return value;
}
void
pci_write_config(device_t dev, int offset, uint32_t value, int size)
{
pci_info *info = &((struct root_device_softc *)dev->root->softc)->pci_info;
TRACE_PCI(dev, "pci_write_config(%i, 0x%x, %i)\n", offset, value, size);
gPci->write_pci_config(info->bus, info->device, info->function, offset,
size, value);
}
uint16_t
pci_get_vendor(device_t dev)
{
return pci_read_config(dev, PCI_vendor_id, 2);
}
uint16_t
pci_get_device(device_t dev)
{
return pci_read_config(dev, PCI_device_id, 2);
}
uint16_t
pci_get_subvendor(device_t dev)
{
return pci_read_config(dev, PCI_subsystem_vendor_id, 2);
}
uint16_t
pci_get_subdevice(device_t dev)
{
return pci_read_config(dev, PCI_subsystem_id, 2);
}
uint8_t
pci_get_revid(device_t dev)
{
return pci_read_config(dev, PCI_revision, 1);
}
static void
pci_set_command_bit(device_t dev, uint16_t bit)
{
uint16_t command = pci_read_config(dev, PCI_command, 2);
pci_write_config(dev, PCI_command, command | bit, 2);
}
int
pci_enable_busmaster(device_t dev)
{
pci_set_command_bit(dev, PCI_command_master);
return 0;
}
int
pci_enable_io(device_t dev, int space)
{
/* adapted from FreeBSD's pci_enable_io_method */
int bit = 0;
switch (space) {
case SYS_RES_IOPORT:
bit = PCI_command_io;
break;
case SYS_RES_MEMORY:
bit = PCI_command_memory;
break;
default:
return EINVAL;
}
pci_set_command_bit(dev, bit);
if (pci_read_config(dev, PCI_command, 2) & bit)
return 0;
device_printf(dev, "pci_enable_io(%d) failed.\n", space);
return ENXIO;
}
int
pci_find_extcap(device_t child, int capability, int *_capabilityRegister)
{
uint8 capabilityPointer;
uint8 headerType;
uint16 status;
status = pci_read_config(child, PCIR_STATUS, 2);
if ((status & PCIM_STATUS_CAPPRESENT) == 0)
return ENXIO;
headerType = pci_read_config(child, PCI_header_type, 1);
switch (headerType & PCIM_HDRTYPE) {
case 0:
case 1:
capabilityPointer = PCIR_CAP_PTR;
break;
case 2:
capabilityPointer = PCIR_CAP_PTR_2;
break;
default:
return ENXIO;
}
capabilityPointer = pci_read_config(child, capabilityPointer, 1);
while (capabilityPointer != 0) {
if (pci_read_config(child, capabilityPointer + PCICAP_ID, 1)
== capability) {
if (_capabilityRegister != NULL)
*_capabilityRegister = capabilityPointer;
return 0;
}
capabilityPointer = pci_read_config(child,
capabilityPointer + PCICAP_NEXTPTR, 1);
}
return ENOENT;
}
int
pci_msi_count(device_t dev)
{
return 0;
}
int
pci_alloc_msi(device_t dev, int *count)
{
return ENODEV;
}
int
pci_release_msi(device_t dev)
{
return ENODEV;
}
int
pci_msix_count(device_t dev)
{
return 0;
}
int
pci_alloc_msix(device_t dev, int *count)
{
return ENODEV;
}