From 58782ca1470526a2729126a2f88d8dfd0c7f72f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sat, 21 Aug 2010 14:47:38 +0000 Subject: [PATCH] pci: Fix line endings of ppc code No functional changes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38295 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../ppc/openfirmware/pci_openfirmware.cpp | 212 +++---- .../arch/ppc/openfirmware/pci_openfirmware.h | 26 +- .../ppc/openfirmware/pci_openfirmware_priv.h | 100 +-- .../pci/arch/ppc/openfirmware/uninorth.cpp | 568 +++++++++--------- .../kernel/bus_managers/pci/arch/ppc/pci_io.h | 194 +++--- 5 files changed, 550 insertions(+), 550 deletions(-) diff --git a/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/pci_openfirmware.cpp b/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/pci_openfirmware.cpp index bacb3c9047..1e624a703a 100644 --- a/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/pci_openfirmware.cpp +++ b/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/pci_openfirmware.cpp @@ -1,106 +1,106 @@ -/* - * Copyright 2006, Ingo Weinhold . - * All rights reserved. Distributed under the terms of the MIT License. - */ - -#include "pci_openfirmware.h" - -#include -#include - -#include - -#include -#include -#include - -#include "pci_openfirmware_priv.h" - - -typedef status_t (*probeFunction)(int, const StringArrayPropertyValue&); - -static const probeFunction sProbeFunctions[] = { - ppc_openfirmware_probe_uninorth, - NULL, -}; - - -status_t -ppc_openfirmware_pci_controller_init(void) -{ - char path[256]; - int cookie = 0; - while (of_get_next_device(&cookie, NULL, "pci", path, sizeof(path)) - == B_OK) { -dprintf("ppc_openfirmware_pci_controller_init(): pci device node: %s\n", path); - // get the device node and the "compatible" property - int deviceNode = of_finddevice(path); - StringArrayPropertyValue compatible; - status_t error = openfirmware_get_property(deviceNode, "compatible", - compatible); - if (error != B_OK) { - dprintf("ppc_openfirmware_pci_controller_init: Failed to get " - "\"compatible\" property for pci device: %s\n", path); - continue; - } - - // probe - for (int i = 0; sProbeFunctions[i]; i++) { - error = sProbeFunctions[i](deviceNode, compatible); - if (error == B_OK) - break; - } - } - - return B_OK; -} - - -// #pragma mark - support functions - - -char * -StringArrayPropertyValue::NextElement(int &cookie) const -{ - if (cookie >= length) - return NULL; - - char *result = value + cookie; - cookie += strnlen(result, length - cookie) + 1; - return result; -} - - -bool -StringArrayPropertyValue::ContainsElement(const char *value) const -{ - int cookie = 0; - while (char *checkValue = NextElement(cookie)) { - if (strcmp(checkValue, value) == 0) - return true; - } - - return false; -} - - -status_t -openfirmware_get_property(int package, const char *propertyName, - PropertyValue &value) -{ - value.length = of_getproplen(package, propertyName); - if (value.length < 0) - return B_ENTRY_NOT_FOUND; - - value.value = (char*)malloc(value.length); - if (!value.value) - return B_NO_MEMORY; - - if (of_getprop(package, propertyName, value.value, value.length) - == OF_FAILED) { - return B_ERROR; - } - - return B_OK; -} - +/* + * Copyright 2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "pci_openfirmware.h" + +#include +#include + +#include + +#include +#include +#include + +#include "pci_openfirmware_priv.h" + + +typedef status_t (*probeFunction)(int, const StringArrayPropertyValue&); + +static const probeFunction sProbeFunctions[] = { + ppc_openfirmware_probe_uninorth, + NULL, +}; + + +status_t +ppc_openfirmware_pci_controller_init(void) +{ + char path[256]; + int cookie = 0; + while (of_get_next_device(&cookie, NULL, "pci", path, sizeof(path)) + == B_OK) { +dprintf("ppc_openfirmware_pci_controller_init(): pci device node: %s\n", path); + // get the device node and the "compatible" property + int deviceNode = of_finddevice(path); + StringArrayPropertyValue compatible; + status_t error = openfirmware_get_property(deviceNode, "compatible", + compatible); + if (error != B_OK) { + dprintf("ppc_openfirmware_pci_controller_init: Failed to get " + "\"compatible\" property for pci device: %s\n", path); + continue; + } + + // probe + for (int i = 0; sProbeFunctions[i]; i++) { + error = sProbeFunctions[i](deviceNode, compatible); + if (error == B_OK) + break; + } + } + + return B_OK; +} + + +// #pragma mark - support functions + + +char * +StringArrayPropertyValue::NextElement(int &cookie) const +{ + if (cookie >= length) + return NULL; + + char *result = value + cookie; + cookie += strnlen(result, length - cookie) + 1; + return result; +} + + +bool +StringArrayPropertyValue::ContainsElement(const char *value) const +{ + int cookie = 0; + while (char *checkValue = NextElement(cookie)) { + if (strcmp(checkValue, value) == 0) + return true; + } + + return false; +} + + +status_t +openfirmware_get_property(int package, const char *propertyName, + PropertyValue &value) +{ + value.length = of_getproplen(package, propertyName); + if (value.length < 0) + return B_ENTRY_NOT_FOUND; + + value.value = (char*)malloc(value.length); + if (!value.value) + return B_NO_MEMORY; + + if (of_getprop(package, propertyName, value.value, value.length) + == OF_FAILED) { + return B_ERROR; + } + + return B_OK; +} + diff --git a/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/pci_openfirmware.h b/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/pci_openfirmware.h index 4afbd58ec8..5427963999 100644 --- a/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/pci_openfirmware.h +++ b/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/pci_openfirmware.h @@ -1,13 +1,13 @@ -/* - * Copyright 2006, Ingo Weinhold . - * All rights reserved. Distributed under the terms of the MIT License. - */ - -#ifndef PCI_BUS_MANAGER_PPC_OPEN_FIRMWARE_H -#define PCI_BUS_MANAGER_PPC_OPEN_FIRMWARE_H - -#include - -status_t ppc_openfirmware_pci_controller_init(void); - -#endif // PCI_BUS_MANAGER_PPC_OPEN_FIRMWARE_H +/* + * Copyright 2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#ifndef PCI_BUS_MANAGER_PPC_OPEN_FIRMWARE_H +#define PCI_BUS_MANAGER_PPC_OPEN_FIRMWARE_H + +#include + +status_t ppc_openfirmware_pci_controller_init(void); + +#endif // PCI_BUS_MANAGER_PPC_OPEN_FIRMWARE_H diff --git a/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/pci_openfirmware_priv.h b/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/pci_openfirmware_priv.h index bd57c6ac74..a32a959f82 100644 --- a/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/pci_openfirmware_priv.h +++ b/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/pci_openfirmware_priv.h @@ -1,50 +1,50 @@ -/* - * Copyright 2006, Ingo Weinhold . - * All rights reserved. Distributed under the terms of the MIT License. - */ - -#ifndef PCI_BUS_MANAGER_PPC_OPEN_FIRMWARE_PRIV_H -#define PCI_BUS_MANAGER_PPC_OPEN_FIRMWARE_PRIV_H - -#include -#include - -#include - - -struct StringArrayPropertyValue; - - -// implementations - -status_t ppc_openfirmware_probe_uninorth(int deviceNode, - const StringArrayPropertyValue &compatibleValue); - - -// property support - -struct PropertyValue { - PropertyValue() - : value(NULL) - { - } - - ~PropertyValue() - { - free(value); - } - - char *value; - int length; -}; - -struct StringArrayPropertyValue : PropertyValue { - - char *NextElement(int &cookie) const; - bool ContainsElement(const char *value) const; -}; - -status_t openfirmware_get_property(int package, const char *propertyName, - PropertyValue &value); - -#endif // PCI_BUS_MANAGER_PPC_OPEN_FIRMWARE_PRIV_H +/* + * Copyright 2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#ifndef PCI_BUS_MANAGER_PPC_OPEN_FIRMWARE_PRIV_H +#define PCI_BUS_MANAGER_PPC_OPEN_FIRMWARE_PRIV_H + +#include +#include + +#include + + +struct StringArrayPropertyValue; + + +// implementations + +status_t ppc_openfirmware_probe_uninorth(int deviceNode, + const StringArrayPropertyValue &compatibleValue); + + +// property support + +struct PropertyValue { + PropertyValue() + : value(NULL) + { + } + + ~PropertyValue() + { + free(value); + } + + char *value; + int length; +}; + +struct StringArrayPropertyValue : PropertyValue { + + char *NextElement(int &cookie) const; + bool ContainsElement(const char *value) const; +}; + +status_t openfirmware_get_property(int package, const char *propertyName, + PropertyValue &value); + +#endif // PCI_BUS_MANAGER_PPC_OPEN_FIRMWARE_PRIV_H diff --git a/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/uninorth.cpp b/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/uninorth.cpp index 4f30406170..bc59cfb409 100644 --- a/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/uninorth.cpp +++ b/src/add-ons/kernel/bus_managers/pci/arch/ppc/openfirmware/uninorth.cpp @@ -1,284 +1,284 @@ -/* - * Copyright 2006, Ingo Weinhold . - * All rights reserved. Distributed under the terms of the MIT License. - */ -/*- - * Copyright (C) 2002 Benno Rice. - * 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 Benno Rice ``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 TOOLS GMBH 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. - * - * $FreeBSD$ - */ - -#include -#include - -#include - -#include -#include -#include - -#include "pci_controller.h" -#include "pci_io.h" -#include "pci_openfirmware_priv.h" - - -struct uninorth_range { - uint32 pci_hi; - uint32 pci_mid; - uint32 pci_lo; - uint32 host; - uint32 size_hi; - uint32 size_lo; -}; - -struct uninorth_host_bridge { - int device_node; - addr_t address_registers; - addr_t data_registers; - uint32 bus; - struct uninorth_range ranges[6]; - int range_count; -}; - - -#define out8rb(address, value) ppc_out8((vuint8*)(address), value) -#define out16rb(address, value) ppc_out16_reverse((vuint16*)(address), value) -#define out32rb(address, value) ppc_out32_reverse((vuint32*)(address), value) -#define in8rb(address) ppc_in8((const vuint8*)(address)) -#define in16rb(address) ppc_in16_reverse((const vuint16*)(address)) -#define in32rb(address) ppc_in32_reverse((const vuint32*)(address)) - - -static int uninorth_enable_config(struct uninorth_host_bridge *bridge, - uint8 bus, uint8 slot, uint8 function, uint8 offset); - -static status_t uninorth_read_pci_config(void *cookie, uint8 bus, uint8 device, - uint8 function, uint8 offset, uint8 size, uint32 *value); -static status_t uninorth_write_pci_config(void *cookie, uint8 bus, - uint8 device, uint8 function, uint8 offset, uint8 size, - uint32 value); -static status_t uninorth_get_max_bus_devices(void *cookie, int32 *count); -static status_t uninorth_read_pci_irq(void *cookie, uint8 bus, uint8 device, - uint8 function, uint8 pin, uint8 *irq); -static status_t uninorth_write_pci_irq(void *cookie, uint8 bus, uint8 device, - uint8 function, uint8 pin, uint8 irq); - -static pci_controller sUniNorthPCIController = { - uninorth_read_pci_config, - uninorth_write_pci_config, - uninorth_get_max_bus_devices, - uninorth_read_pci_irq, - uninorth_write_pci_irq, -}; - - -static status_t -uninorth_read_pci_config(void *cookie, uint8 bus, uint8 device, uint8 function, - uint8 offset, uint8 size, uint32 *value) -{ - uninorth_host_bridge *bridge = (uninorth_host_bridge*)cookie; - - addr_t caoff = bridge->data_registers + (offset & 0x07); - - if (uninorth_enable_config(bridge, bus, device, function, offset) != 0) { - switch (size) { - case 1: - *value = in8rb(caoff); - break; - case 2: - *value = in16rb(caoff); - break; - case 4: - *value = in32rb(caoff); - break; - default: - *value = 0xffffffff; - break; - } - } else - *value = 0xffffffff; - - return B_OK; -} - - -static status_t uninorth_write_pci_config(void *cookie, uint8 bus, uint8 device, - uint8 function, uint8 offset, uint8 size, uint32 value) -{ - uninorth_host_bridge *bridge = (uninorth_host_bridge*)cookie; - - addr_t caoff = bridge->data_registers + (offset & 0x07); - - if (uninorth_enable_config(bridge, bus, device, function, offset)) { - switch (size) { - case 1: - out8rb(caoff, (uint8)value); - (void)in8rb(caoff); - break; - case 2: - out16rb(caoff, (uint16)value); - (void)in16rb(caoff); - break; - case 4: - out32rb(caoff, value); - (void)in32rb(caoff); - break; - } - } - - return B_OK; -} - - -static status_t uninorth_get_max_bus_devices(void *cookie, int32 *count) -{ - *count = 32; - return B_OK; -} - - -static status_t uninorth_read_pci_irq(void *cookie, uint8 bus, uint8 device, - uint8 function, uint8 pin, uint8 *irq) -{ - return B_ERROR; -} - - -static status_t uninorth_write_pci_irq(void *cookie, uint8 bus, uint8 device, - uint8 function, uint8 pin, uint8 irq) -{ - return B_ERROR; -} - - -// #pragma mark - - - -static int -uninorth_enable_config(struct uninorth_host_bridge *bridge, uint8 bus, - uint8 slot, uint8 function, uint8 offset) -{ -// uint32 pass; -// if (resource_int_value(device_get_name(sc->sc_dev), -// device_get_unit(sc->sc_dev), "skipslot", &pass) == 0) { -// if (pass == slot) -// return (0); -// } - - uint32 cfgval; - if (bridge->bus == bus) { - /* - * No slots less than 11 on the primary bus - */ - if (slot < 11) - return (0); - - cfgval = (1 << slot) | (function << 8) | (offset & 0xfc); - } else { - cfgval = (bus << 16) | (slot << 11) | (function << 8) | - (offset & 0xfc) | 1; - } - - do { - out32rb(bridge->address_registers, cfgval); - } while (in32rb(bridge->address_registers) != cfgval); - - return (1); -} - - -// #pragma mark - - -status_t -ppc_openfirmware_probe_uninorth(int deviceNode, - const StringArrayPropertyValue &compatibleValue) -{ - if (!compatibleValue.ContainsElement("uni-north")) - return B_ERROR; - - uint32 reg[2]; - if (of_getprop(deviceNode, "reg", reg, sizeof(reg)) < 8) - return B_ERROR; - - uint32 busrange[2]; - if (of_getprop(deviceNode, "bus-range", busrange, sizeof(busrange)) != 8) - return B_ERROR; - - uninorth_host_bridge *bridge - = (uninorth_host_bridge*)malloc(sizeof(uninorth_host_bridge)); - if (!bridge) - return B_NO_MEMORY; - - bridge->device_node = deviceNode; - bridge->address_registers = reg[0] + 0x800000; - bridge->data_registers = reg[0] + 0xc00000; - bridge->bus = busrange[0]; -// TODO: Check whether address and data registers have already been mapped by -// the Open Firmware. If not, map them ourselves. - - memset(bridge->ranges, 0, sizeof(bridge->ranges)); - int bytesRead = of_getprop(deviceNode, "ranges", bridge->ranges, - sizeof(bridge->ranges)); - - if (bytesRead < 0) { - dprintf("ppc_openfirmware_probe_uninorth: Could not get ranges.\n"); - return B_ERROR; - } - bridge->range_count = bytesRead / sizeof(uninorth_range); - - uninorth_range *ioRange = NULL; - uninorth_range *memoryRanges[2]; - int memoryRangeCount = 0; - - for (int i = 0; i < bridge->range_count; i++) { - uninorth_range *range = bridge->ranges + i; - switch (range->pci_hi & OFW_PCI_PHYS_HI_SPACEMASK) { - case OFW_PCI_PHYS_HI_SPACE_CONFIG: - break; - case OFW_PCI_PHYS_HI_SPACE_IO: - ioRange = range; - break; - case OFW_PCI_PHYS_HI_SPACE_MEM32: - memoryRanges[memoryRangeCount++] = range; - break; - case OFW_PCI_PHYS_HI_SPACE_MEM64: - break; - } - } - - if (ioRange == NULL) { - dprintf("ppc_openfirmware_probe_uninorth: Can't find io range.\n"); - return B_ERROR; - } - - if (memoryRangeCount == 0) { - dprintf("ppc_openfirmware_probe_uninorth: Can't find mem ranges.\n"); - return B_ERROR; - } - - status_t error = pci_controller_add(&sUniNorthPCIController, bridge); - if (error != B_OK) - free(bridge); - return error; -} +/* + * Copyright 2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ +/*- + * Copyright (C) 2002 Benno Rice. + * 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 Benno Rice ``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 TOOLS GMBH 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. + * + * $FreeBSD$ + */ + +#include +#include + +#include + +#include +#include +#include + +#include "pci_controller.h" +#include "pci_io.h" +#include "pci_openfirmware_priv.h" + + +struct uninorth_range { + uint32 pci_hi; + uint32 pci_mid; + uint32 pci_lo; + uint32 host; + uint32 size_hi; + uint32 size_lo; +}; + +struct uninorth_host_bridge { + int device_node; + addr_t address_registers; + addr_t data_registers; + uint32 bus; + struct uninorth_range ranges[6]; + int range_count; +}; + + +#define out8rb(address, value) ppc_out8((vuint8*)(address), value) +#define out16rb(address, value) ppc_out16_reverse((vuint16*)(address), value) +#define out32rb(address, value) ppc_out32_reverse((vuint32*)(address), value) +#define in8rb(address) ppc_in8((const vuint8*)(address)) +#define in16rb(address) ppc_in16_reverse((const vuint16*)(address)) +#define in32rb(address) ppc_in32_reverse((const vuint32*)(address)) + + +static int uninorth_enable_config(struct uninorth_host_bridge *bridge, + uint8 bus, uint8 slot, uint8 function, uint8 offset); + +static status_t uninorth_read_pci_config(void *cookie, uint8 bus, uint8 device, + uint8 function, uint8 offset, uint8 size, uint32 *value); +static status_t uninorth_write_pci_config(void *cookie, uint8 bus, + uint8 device, uint8 function, uint8 offset, uint8 size, + uint32 value); +static status_t uninorth_get_max_bus_devices(void *cookie, int32 *count); +static status_t uninorth_read_pci_irq(void *cookie, uint8 bus, uint8 device, + uint8 function, uint8 pin, uint8 *irq); +static status_t uninorth_write_pci_irq(void *cookie, uint8 bus, uint8 device, + uint8 function, uint8 pin, uint8 irq); + +static pci_controller sUniNorthPCIController = { + uninorth_read_pci_config, + uninorth_write_pci_config, + uninorth_get_max_bus_devices, + uninorth_read_pci_irq, + uninorth_write_pci_irq, +}; + + +static status_t +uninorth_read_pci_config(void *cookie, uint8 bus, uint8 device, uint8 function, + uint8 offset, uint8 size, uint32 *value) +{ + uninorth_host_bridge *bridge = (uninorth_host_bridge*)cookie; + + addr_t caoff = bridge->data_registers + (offset & 0x07); + + if (uninorth_enable_config(bridge, bus, device, function, offset) != 0) { + switch (size) { + case 1: + *value = in8rb(caoff); + break; + case 2: + *value = in16rb(caoff); + break; + case 4: + *value = in32rb(caoff); + break; + default: + *value = 0xffffffff; + break; + } + } else + *value = 0xffffffff; + + return B_OK; +} + + +static status_t uninorth_write_pci_config(void *cookie, uint8 bus, uint8 device, + uint8 function, uint8 offset, uint8 size, uint32 value) +{ + uninorth_host_bridge *bridge = (uninorth_host_bridge*)cookie; + + addr_t caoff = bridge->data_registers + (offset & 0x07); + + if (uninorth_enable_config(bridge, bus, device, function, offset)) { + switch (size) { + case 1: + out8rb(caoff, (uint8)value); + (void)in8rb(caoff); + break; + case 2: + out16rb(caoff, (uint16)value); + (void)in16rb(caoff); + break; + case 4: + out32rb(caoff, value); + (void)in32rb(caoff); + break; + } + } + + return B_OK; +} + + +static status_t uninorth_get_max_bus_devices(void *cookie, int32 *count) +{ + *count = 32; + return B_OK; +} + + +static status_t uninorth_read_pci_irq(void *cookie, uint8 bus, uint8 device, + uint8 function, uint8 pin, uint8 *irq) +{ + return B_ERROR; +} + + +static status_t uninorth_write_pci_irq(void *cookie, uint8 bus, uint8 device, + uint8 function, uint8 pin, uint8 irq) +{ + return B_ERROR; +} + + +// #pragma mark - + + +static int +uninorth_enable_config(struct uninorth_host_bridge *bridge, uint8 bus, + uint8 slot, uint8 function, uint8 offset) +{ +// uint32 pass; +// if (resource_int_value(device_get_name(sc->sc_dev), +// device_get_unit(sc->sc_dev), "skipslot", &pass) == 0) { +// if (pass == slot) +// return (0); +// } + + uint32 cfgval; + if (bridge->bus == bus) { + /* + * No slots less than 11 on the primary bus + */ + if (slot < 11) + return (0); + + cfgval = (1 << slot) | (function << 8) | (offset & 0xfc); + } else { + cfgval = (bus << 16) | (slot << 11) | (function << 8) | + (offset & 0xfc) | 1; + } + + do { + out32rb(bridge->address_registers, cfgval); + } while (in32rb(bridge->address_registers) != cfgval); + + return (1); +} + + +// #pragma mark - + +status_t +ppc_openfirmware_probe_uninorth(int deviceNode, + const StringArrayPropertyValue &compatibleValue) +{ + if (!compatibleValue.ContainsElement("uni-north")) + return B_ERROR; + + uint32 reg[2]; + if (of_getprop(deviceNode, "reg", reg, sizeof(reg)) < 8) + return B_ERROR; + + uint32 busrange[2]; + if (of_getprop(deviceNode, "bus-range", busrange, sizeof(busrange)) != 8) + return B_ERROR; + + uninorth_host_bridge *bridge + = (uninorth_host_bridge*)malloc(sizeof(uninorth_host_bridge)); + if (!bridge) + return B_NO_MEMORY; + + bridge->device_node = deviceNode; + bridge->address_registers = reg[0] + 0x800000; + bridge->data_registers = reg[0] + 0xc00000; + bridge->bus = busrange[0]; +// TODO: Check whether address and data registers have already been mapped by +// the Open Firmware. If not, map them ourselves. + + memset(bridge->ranges, 0, sizeof(bridge->ranges)); + int bytesRead = of_getprop(deviceNode, "ranges", bridge->ranges, + sizeof(bridge->ranges)); + + if (bytesRead < 0) { + dprintf("ppc_openfirmware_probe_uninorth: Could not get ranges.\n"); + return B_ERROR; + } + bridge->range_count = bytesRead / sizeof(uninorth_range); + + uninorth_range *ioRange = NULL; + uninorth_range *memoryRanges[2]; + int memoryRangeCount = 0; + + for (int i = 0; i < bridge->range_count; i++) { + uninorth_range *range = bridge->ranges + i; + switch (range->pci_hi & OFW_PCI_PHYS_HI_SPACEMASK) { + case OFW_PCI_PHYS_HI_SPACE_CONFIG: + break; + case OFW_PCI_PHYS_HI_SPACE_IO: + ioRange = range; + break; + case OFW_PCI_PHYS_HI_SPACE_MEM32: + memoryRanges[memoryRangeCount++] = range; + break; + case OFW_PCI_PHYS_HI_SPACE_MEM64: + break; + } + } + + if (ioRange == NULL) { + dprintf("ppc_openfirmware_probe_uninorth: Can't find io range.\n"); + return B_ERROR; + } + + if (memoryRangeCount == 0) { + dprintf("ppc_openfirmware_probe_uninorth: Can't find mem ranges.\n"); + return B_ERROR; + } + + status_t error = pci_controller_add(&sUniNorthPCIController, bridge); + if (error != B_OK) + free(bridge); + return error; +} diff --git a/src/add-ons/kernel/bus_managers/pci/arch/ppc/pci_io.h b/src/add-ons/kernel/bus_managers/pci/arch/ppc/pci_io.h index a0bf8e82de..a37447ad62 100644 --- a/src/add-ons/kernel/bus_managers/pci/arch/ppc/pci_io.h +++ b/src/add-ons/kernel/bus_managers/pci/arch/ppc/pci_io.h @@ -1,97 +1,97 @@ -/* - * Copyright 2006, Ingo Weinhold . - * All rights reserved. Distributed under the terms of the MIT License. - */ - -#ifndef PCI_BUS_MANAGER_PPC_IO_H -#define PCI_BUS_MANAGER_PPC_IO_H - -#include - -static inline void -ppc_out8(vuint8 *address, uint8 value) -{ - *address = value; - asm volatile("eieio; sync"); -} - - -static inline void -ppc_out16(vuint16 *address, uint16 value) -{ - *address = value; - asm volatile("eieio; sync"); -} - - -static inline void -ppc_out16_reverse(vuint16 *address, uint16 value) -{ - asm volatile("sthbrx %1, 0, %0" : : "r"(address), "r"(value)); - asm volatile("eieio; sync"); -} - - -static inline void -ppc_out32(vuint32 *address, uint32 value) -{ - *address = value; - asm volatile("eieio; sync"); -} - - -static inline void -ppc_out32_reverse(vuint32 *address, uint32 value) -{ - asm volatile("stwbrx %1, 0, %0" : : "r"(address), "r"(value)); - asm volatile("eieio; sync"); -} - - -static inline uint8 -ppc_in8(const vuint8 *address) -{ - uint8 value = *address; - asm volatile("eieio; sync"); - return value; -} - - -static inline uint16 -ppc_in16(const vuint16 *address) -{ - uint16 value = *address; - asm volatile("eieio; sync"); - return value; -} - - -static inline uint16 -ppc_in16_reverse(const vuint16 *address) -{ - uint16 value; - asm volatile("lhbrx %0, 0, %1" : "=r"(value) : "r"(address)); - asm volatile("eieio; sync"); - return value; -} - - -static inline uint32 -ppc_in32(const vuint32 *address) -{ - uint32 value = *address; - asm volatile("eieio; sync"); - return value; -} - - -static inline uint32 -ppc_in32_reverse(const vuint32 *address) -{ - uint32 value; - asm volatile("lwbrx %0, 0, %1" : "=r"(value) : "r"(address)); - asm volatile("eieio; sync"); - return value; -} - -#endif // PCI_BUS_MANAGER_PPC_IO_H +/* + * Copyright 2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#ifndef PCI_BUS_MANAGER_PPC_IO_H +#define PCI_BUS_MANAGER_PPC_IO_H + +#include + +static inline void +ppc_out8(vuint8 *address, uint8 value) +{ + *address = value; + asm volatile("eieio; sync"); +} + + +static inline void +ppc_out16(vuint16 *address, uint16 value) +{ + *address = value; + asm volatile("eieio; sync"); +} + + +static inline void +ppc_out16_reverse(vuint16 *address, uint16 value) +{ + asm volatile("sthbrx %1, 0, %0" : : "r"(address), "r"(value)); + asm volatile("eieio; sync"); +} + + +static inline void +ppc_out32(vuint32 *address, uint32 value) +{ + *address = value; + asm volatile("eieio; sync"); +} + + +static inline void +ppc_out32_reverse(vuint32 *address, uint32 value) +{ + asm volatile("stwbrx %1, 0, %0" : : "r"(address), "r"(value)); + asm volatile("eieio; sync"); +} + + +static inline uint8 +ppc_in8(const vuint8 *address) +{ + uint8 value = *address; + asm volatile("eieio; sync"); + return value; +} + + +static inline uint16 +ppc_in16(const vuint16 *address) +{ + uint16 value = *address; + asm volatile("eieio; sync"); + return value; +} + + +static inline uint16 +ppc_in16_reverse(const vuint16 *address) +{ + uint16 value; + asm volatile("lhbrx %0, 0, %1" : "=r"(value) : "r"(address)); + asm volatile("eieio; sync"); + return value; +} + + +static inline uint32 +ppc_in32(const vuint32 *address) +{ + uint32 value = *address; + asm volatile("eieio; sync"); + return value; +} + + +static inline uint32 +ppc_in32_reverse(const vuint32 *address) +{ + uint32 value; + asm volatile("lwbrx %0, 0, %1" : "=r"(value) : "r"(address)); + asm volatile("eieio; sync"); + return value; +} + +#endif // PCI_BUS_MANAGER_PPC_IO_H