Changes in / [b39fd4c:75a2dc08] in mainline
- Files:
-
- 34 added
- 14 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/arch/ia32/Makefile.inc
rb39fd4c r75a2dc08 60 60 $(USPACEDIR)/app/trace/trace \ 61 61 $(USPACEDIR)/app/klog/klog \ 62 $(USPACEDIR)/app/bdsh/bdsh 62 $(USPACEDIR)/app/bdsh/bdsh \ 63 $(USPACEDIR)/app/lspci/lspci \ 64 $(USPACEDIR)/app/shutters/shutters 63 65 64 66 build: $(BASE)/image.iso -
boot/arch/sparc64/loader/Makefile
rb39fd4c r75a2dc08 102 102 $(USPACEDIR)/srv/kbd/kbd \ 103 103 $(USPACEDIR)/srv/console/console \ 104 $(USPACEDIR)/srv/pci/pci \ 104 105 $(USPACEDIR)/srv/fs/devfs/devfs \ 105 106 $(USPACEDIR)/srv/fs/tmpfs/tmpfs \ … … 118 119 $(USPACEDIR)/app/trace/trace \ 119 120 $(USPACEDIR)/app/bdsh/bdsh \ 120 $(USPACEDIR)/app/klog/klog 121 $(USPACEDIR)/app/klog/klog \ 122 $(USPACEDIR)/app/lspci/lspci 121 123 122 124 ifeq ($(MACHINE),generic) -
uspace/Makefile
rb39fd4c r75a2dc08 53 53 srv/devmap \ 54 54 app/tetris \ 55 app/shutters \ 55 56 app/tester \ 56 57 app/trace \ … … 61 62 62 63 ifeq ($(UARCH),amd64) 63 DIRS += srv/pci 64 DIRS += \ 65 srv/pci \ 66 app/lspci 64 67 endif 65 68 66 69 ifeq ($(UARCH),ia32) 67 DIRS += srv/pci 70 DIRS += \ 71 srv/pci \ 72 app/lspci 68 73 endif 69 74 70 75 ifeq ($(UARCH),sparc64) 71 76 DIRS += \ 77 srv/pci \ 78 app/lspci \ 72 79 srv/cir/fhc \ 73 80 srv/cir/obio -
uspace/app/init/init.c
rb39fd4c r75a2dc08 264 264 getvc("vc6", "/app/klog"); 265 265 266 usleep(1000000); 267 spawn("/srv/pci"); 268 266 269 return 0; 267 270 } -
uspace/srv/pci/Makefile
rb39fd4c r75a2dc08 35 35 include $(LIBC_PREFIX)/Makefile.toolchain 36 36 37 CFLAGS += -I../libipc/include 37 38 38 LIBS = libpci/libpci.a$(LIBC_PREFIX)/libc.a39 LIBS = $(LIBC_PREFIX)/libc.a 39 40 40 41 ## Sources … … 43 44 OUTPUT = pci 44 45 SOURCES = \ 45 pci.c 46 main.c \ 47 pci.c \ 48 intel_piix3.c \ 49 isa.c \ 50 serial.c 51 52 ifeq ($(PROCESSOR), us) 53 SOURCES += psycho.c 54 endif 55 56 ifeq ($(UARCH), ia32) 57 SOURCES += intel_method1.c 58 endif 59 60 CFLAGS += -D$(UARCH) 46 61 47 62 OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) … … 49 64 .PHONY: all clean depend disasm 50 65 51 all: $(OUTPUT) disasm66 all: $(OUTPUT) $(OUTPUT).disasm 52 67 53 68 -include Makefile.depend … … 55 70 clean: 56 71 -rm -f $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend $(OBJECTS) 57 $(MAKE) -C libpci clean58 72 59 73 depend: … … 61 75 62 76 $(OUTPUT): $(OBJECTS) $(LIBS) 63 $(MAKE) -C libpci64 77 $(LD) -T $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map 65 78 66 disasm: 67 $(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm 79 disasm: $(OUTPUT).disasm 80 81 $(OUTPUT).disasm: $(OUTPUT) 82 $(OBJDUMP) -d $< >$@ 68 83 69 84 %.o: %.S … … 75 90 %.o: %.c 76 91 $(CC) $(DEFS) $(CFLAGS) -c $< -o $@ 77 78 libpci/libpci.a:79 $(MAKE) -C libpci -
uspace/srv/pci/pci.c
rb39fd4c r75a2dc08 1 #include <futex.h> 2 #include <assert.h> 3 4 #include "pci.h" 5 #include "pci_bus.h" 6 #include "pci_regs.h" 7 #include "pci_conf.h" 8 9 #define NAME "PCI" 10 11 LIST_INITIALIZE(devices_list); 12 LIST_INITIALIZE(buses_list); 13 LIST_INITIALIZE(drivers_list); 14 15 static atomic_t pci_bus_futex = FUTEX_INITIALIZER; 16 17 static int pci_match(pci_drv_t *drv, pci_dev_t *dev); 18 static int pci_pass_dev(pci_drv_t *drv, pci_dev_t *dev); 19 static void pci_lookup_driver(pci_dev_t *dev); 20 static void pci_lookup_devices(pci_drv_t *drv); 21 22 23 void pci_bus_scan(pci_bus_t *bus) 24 { 25 pci_dev_t *dev = pci_alloc_dev(); 26 pci_bus_t *child_bus = NULL; 27 int dnum, fnum, bus_num; 28 bool multi; 29 uint8_t header_type; 30 31 for (dnum = 0; dnum < 32; dnum++) { 32 multi = true; 33 for (fnum = 0; multi && fnum < 8; fnum++) { 34 pci_init_dev(dev, bus, dnum, fnum); 35 dev->vendor_id = pci_conf_read_16(dev, PCI_VENDOR_ID); 36 dev->device_id = pci_conf_read_16(dev, PCI_DEVICE_ID); 37 if (dev->vendor_id == 0xFFFF) { // device is not present, go on scanning the bus 38 if (fnum == 0) { 39 break; 40 } else { 41 continue; 42 } 43 } 44 header_type = pci_conf_read_8(dev, PCI_HEADER_TYPE); 45 if (fnum == 0) { 46 multi = header_type >> 7; // is the device multifunction? 47 } 48 header_type = header_type & 0x7F; // clear the multifunction bit 49 50 printf(NAME ": adding new device %3d : %2d : %2d", dev->bus->num, dnum, fnum); 51 printf(" - vendor = 0x%04X, device = 0x%04X.\n", dev->vendor_id, dev->device_id); 52 pci_device_register(dev); 53 54 if (header_type == PCI_HEADER_TYPE_BRIDGE || header_type == PCI_HEADER_TYPE_CARDBUS ) { 55 bus_num = pci_conf_read_8(dev, PCI_BRIDGE_SEC_BUS_NUM); 56 printf(NAME ": device is pci-to-pci bridge, secondary bus number = %d.\n", bus_num); 57 if(bus_num > bus->num) { 58 child_bus = pci_alloc_bus(); 59 pci_init_bus(child_bus, bus, bus_num); 60 pci_bus_register(child_bus); 61 pci_bus_scan(child_bus); 62 } 63 } 64 65 dev = pci_alloc_dev(); // alloc new aux. dev. structure 66 } 67 } 68 69 if (dev->vendor_id == 0xFFFF) { 70 pci_free_dev(dev); // free the auxiliary device structure 71 } 72 } 73 1 74 /* 2 * HelenOS PCI driver. 3 * 4 * (Based on public domain libpci example.c written by Martin Mares.) 5 * Copyright (c) 2006 Jakub Jermar 6 * 7 * Can be freely distributed and used under the terms of the GNU GPL. 8 */ 9 10 /** 11 * @addtogroup pci 12 * @{ 13 */ 14 15 #include <stdio.h> 16 #include <ddi.h> 17 #include <task.h> 18 #include <stdlib.h> 19 #include <ipc/ipc.h> 20 #include <ipc/services.h> 21 #include <errno.h> 22 23 #include "libpci/pci.h" 24 25 #define PCI_CONF1 0xcf8 26 #define PCI_CONF1_SIZE 8 27 28 #define NAME "PCI" 29 30 static struct pci_access *pacc; 31 32 int main(int argc, char *argv[]) 75 * Usage: pci_bus_futex must be down. 76 */ 77 static int pci_pass_dev(pci_drv_t *drv, pci_dev_t *dev) 33 78 { 34 struct pci_dev *dev; 35 unsigned int c; 36 char buf[80]; 37 ipcarg_t ns_in_phone_hash; 38 39 printf("%s: HelenOS PCI driver\n", NAME); 40 41 /* 42 * Gain control over PCI configuration ports. 43 */ 44 iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE); 45 46 pacc = pci_alloc(); /* Get the pci_access structure */ 47 pci_init(pacc); /* Initialize the PCI library */ 48 pci_scan_bus(pacc); /* We want to get the list of devices */ 49 for(dev=pacc->devices; dev; dev=dev->next) { /* Iterate over all devices */ 50 pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_IRQ); 51 c = pci_read_word(dev, PCI_CLASS_DEVICE); /* Read config register directly */ 52 printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d base0=%lx\n", 53 dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id, 54 c, dev->irq, dev->base_addr[0]); 55 printf("\t%s\n", pci_lookup_name(pacc, buf, sizeof(buf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, 56 dev->vendor_id, dev->device_id)); 79 assert(dev->driver == NULL); 80 assert(drv->name != NULL); 81 82 printf(NAME ": passing device to driver '%s'.\n", drv->name); 83 if (drv->ops->add_device != NULL && drv->ops->add_device(dev)) { 84 dev->driver = drv; 85 return 1; 57 86 } 58 59 printf("%s: registering at naming service.\n", NAME); 60 if (ipc_connect_to_me(PHONE_NS, SERVICE_PCI, 0, 0, &ns_in_phone_hash) != 0) { 61 printf("Failed to register %s at naming service.\n", NAME); 62 return -1; 63 } 64 65 printf("%s: accepting connections\n", NAME); 66 while (1) { 67 ipc_call_t call; 68 ipc_callid_t callid; 69 ipcarg_t retval = ENOTSUP; 70 71 callid = ipc_wait_for_call(&call); 72 switch(IPC_GET_METHOD(call)) { 73 case IPC_M_CONNECT_ME_TO: 74 retval = EOK; 75 break; 76 } 77 ipc_answer_0(callid, retval); 78 printf("%s: received call from %lX\n", NAME, 79 call.in_phone_hash); 80 } 81 82 pci_cleanup(pacc); 87 83 88 return 0; 84 89 } 85 90 86 /** 87 * @} 88 */ 91 /* 92 * Usage: pci_bus_futex must be down. 93 */ 94 static void pci_lookup_driver(pci_dev_t *dev) 95 { 96 link_t *item = drivers_list.next; 97 pci_drv_t *drv = NULL; 98 99 while (item != &drivers_list) { 100 drv = list_get_instance(item, pci_drv_t, link); 101 if (pci_match(drv, dev) && pci_pass_dev(drv, dev)) { 102 return; 103 } 104 item = item->next; 105 } 106 } 107 108 /* 109 * Usage: pci_bus_futex must be down. 110 */ 111 static void pci_lookup_devices(pci_drv_t *drv) 112 { 113 link_t *item = devices_list.next; 114 pci_dev_t *dev = NULL; 115 116 printf(NAME ": looking up devices for a newly added driver '%s'.\n", drv->name); 117 118 while (item != &devices_list) { 119 dev = list_get_instance(item, pci_dev_t, link); 120 if (dev->driver == NULL && pci_match(drv, dev)) { 121 pci_pass_dev(drv, dev); 122 } 123 item = item->next; 124 } 125 } 126 127 static int pci_match(pci_drv_t *drv, pci_dev_t *dev) 128 { 129 return drv->vendor_id == dev->vendor_id && drv->device_id == dev->device_id; 130 } 131 132 void pci_bus_register(pci_bus_t *bus) 133 { 134 futex_down(&pci_bus_futex); 135 136 // add the device to the list of pci devices 137 list_append(&(bus->link), &buses_list); 138 139 futex_up(&pci_bus_futex); 140 } 141 142 void pci_device_register(pci_dev_t *dev) 143 { 144 futex_down(&pci_bus_futex); 145 146 // add the device to the list of pci devices 147 list_append(&(dev->link), &devices_list); 148 149 // try to find suitable driver for the device and pass the device to it 150 pci_lookup_driver(dev); 151 152 futex_up(&pci_bus_futex); 153 } 154 155 void pci_driver_register(pci_drv_t *drv) 156 { 157 assert(drv->name != NULL); 158 159 futex_down(&pci_bus_futex); 160 printf(NAME ": registering new driver '%s'.\n", drv->name); 161 list_append(&(drv->link), &drivers_list); 162 163 // try to find compatible devices 164 pci_lookup_devices(drv); 165 166 futex_up(&pci_bus_futex); 167 } 168
Note:
See TracChangeset
for help on using the changeset viewer.