Changeset 4a7c273 in mainline


Ignore:
Timestamp:
2006-05-08T18:24:04Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
20a9b85
Parents:
fca4207
Message:

Port libpci to HelenOS.
List PCI devices on PCI driver startup.

Files:
12 added
5 edited

Legend:

Unmodified
Added
Removed
  • libc/include/stdio.h

    rfca4207 r4a7c273  
    3636
    3737extern int puts(const char * str);
     38extern int putchar(int c);
    3839
    3940extern int printf(const char *fmt, ...);
  • libc/include/stdlib.h

    rfca4207 r4a7c273  
    3434
    3535#define abort() _exit(1)
     36#define exit(status)    _exit((status))
    3637
    3738#endif
  • libc/include/string.h

    rfca4207 r4a7c273  
    3333#include <types.h>
    3434
     35#define bzero(ptr, len) memset((ptr), 0, (len))
     36
    3537void * memset(void *s, int c, size_t n);
    3638void * memcpy(void *dest, void *src, size_t n);
    3739
    3840size_t strlen(const char *str);
     41int strcmp(const char *str1, const char *str2);
     42char *strchr(const char *str, int c);
     43char *strrchr(const char *str, int c);
     44unsigned long strtol(const char *nptr, char **endptr, int base);
    3945
    4046#endif
  • pci/Makefile

    rfca4207 r4a7c273  
    3737CFLAGS += -I../libipc/include
    3838
    39 LIBS = $(LIBIPC_PREFIX)/libipc.a $(LIBC_PREFIX)/libc.a
     39LIBS = libpci/libpci.a $(LIBC_PREFIX)/libc.a
    4040
    4141## Sources
     
    5656clean:
    5757        -rm -f $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend
     58        $(MAKE) -C libpci clean
    5859
    5960depend:
     
    6162
    6263$(OUTPUT): $(OBJECTS) $(LIBS)
     64        $(MAKE) -C libpci
    6365        $(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld  $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
    6466
     
    7476%.o: %.c
    7577        $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     78
     79libpci/libpci.a:
     80        $(MAKE) -C libpci
  • pci/pci.c

    rfca4207 r4a7c273  
    11/*
     2 * HelenOS PCI driver.
     3 *
     4 * Copyright (C) 1997-2003 Martin Mares
    25 * Copyright (C) 2006 Jakub Jermar
    3  * All rights reserved.
    46 *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
     7 * (Based on libpci example.c written by Martin Mares.)
    88 *
    9  * - Redistributions of source code must retain the above copyright
    10  *   notice, this list of conditions and the following disclaimer.
    11  * - Redistributions in binary form must reproduce the above copyright
    12  *   notice, this list of conditions and the following disclaimer in the
    13  *   documentation and/or other materials provided with the distribution.
    14  * - The name of the author may not be used to endorse or promote products
    15  *   derived from this software without specific prior written permission.
    16  *
    17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     9 * Can be freely distributed and used under the terms of the GNU GPL.
    2710 */
    2811
    29 #include <ipc.h>
    3012#include <stdio.h>
    3113#include <ddi.h>
     
    3315#include <stdlib.h>
    3416
     17#include "libpci/pci.h"
     18
     19#define PCI_CONF1       0xcf8
     20#define PCI_CONF1_SIZE  8
     21
    3522int main(int argc, char *argv[])
    3623{
     24        struct pci_access *pacc;
     25        struct pci_dev *dev;
     26        unsigned int c;
     27        char buf[80];
     28
    3729        printf("HelenOS PCI driver\n");
     30
     31        /*
     32         * Gain control over PCI configuration ports.
     33         */
     34        iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE);
     35
     36        pacc = pci_alloc();           /* Get the pci_access structure */
     37        pci_init(pacc);               /* Initialize the PCI library */
     38        pci_scan_bus(pacc);           /* We want to get the list of devices */
     39        for(dev=pacc->devices; dev; dev=dev->next) {   /* Iterate over all devices */
     40                pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);      /* Fill in header info we need */
     41                c = pci_read_word(dev, PCI_CLASS_DEVICE); /* Read config register directly */
     42                printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d base0=%lx\n",
     43                        dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id,
     44                        c, dev->irq, dev->base_addr[0]);
     45                printf("\t%s\n", pci_lookup_name(pacc, buf, sizeof(buf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
     46                        dev->vendor_id, dev->device_id));
     47        }
     48        pci_cleanup(pacc);            /* Close everything */
     49
    3850        return 0;
    3951}
Note: See TracChangeset for help on using the changeset viewer.