Changes in / [fd210de:64cbf94] in mainline
- Files:
-
- 14 added
- 34 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/arch/ia32/Makefile.inc
rfd210de r64cbf94 60 60 $(USPACEDIR)/app/trace/trace \ 61 61 $(USPACEDIR)/app/klog/klog \ 62 $(USPACEDIR)/app/bdsh/bdsh \ 63 $(USPACEDIR)/app/lspci/lspci \ 64 $(USPACEDIR)/app/shutters/shutters 62 $(USPACEDIR)/app/bdsh/bdsh 65 63 66 64 build: $(BASE)/image.iso -
boot/arch/sparc64/loader/Makefile
rfd210de r64cbf94 102 102 $(USPACEDIR)/srv/kbd/kbd \ 103 103 $(USPACEDIR)/srv/console/console \ 104 $(USPACEDIR)/srv/pci/pci \105 104 $(USPACEDIR)/srv/fs/devfs/devfs \ 106 105 $(USPACEDIR)/srv/fs/tmpfs/tmpfs \ … … 119 118 $(USPACEDIR)/app/trace/trace \ 120 119 $(USPACEDIR)/app/bdsh/bdsh \ 121 $(USPACEDIR)/app/klog/klog \ 122 $(USPACEDIR)/app/lspci/lspci 120 $(USPACEDIR)/app/klog/klog 123 121 124 122 ifeq ($(MACHINE),generic) -
uspace/Makefile
rfd210de r64cbf94 53 53 srv/devmap \ 54 54 app/tetris \ 55 app/shutters \56 55 app/tester \ 57 56 app/trace \ … … 62 61 63 62 ifeq ($(UARCH),amd64) 64 DIRS += \ 65 srv/pci \ 66 app/lspci 63 DIRS += srv/pci 67 64 endif 68 65 69 66 ifeq ($(UARCH),ia32) 70 DIRS += \ 71 srv/pci \ 72 app/lspci 67 DIRS += srv/pci 73 68 endif 74 69 75 70 ifeq ($(UARCH),sparc64) 76 71 DIRS += \ 77 srv/pci \78 app/lspci \79 72 srv/cir/fhc \ 80 73 srv/cir/obio -
uspace/app/init/init.c
rfd210de r64cbf94 264 264 getvc("vc6", "/app/klog"); 265 265 266 usleep(1000000);267 spawn("/srv/pci");268 269 266 return 0; 270 267 } -
uspace/srv/pci/Makefile
rfd210de r64cbf94 35 35 include $(LIBC_PREFIX)/Makefile.toolchain 36 36 37 CFLAGS += -I../libipc/include38 37 39 LIBS = $(LIBC_PREFIX)/libc.a38 LIBS = libpci/libpci.a $(LIBC_PREFIX)/libc.a 40 39 41 40 ## Sources … … 44 43 OUTPUT = pci 45 44 SOURCES = \ 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) 45 pci.c 61 46 62 47 OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) … … 64 49 .PHONY: all clean depend disasm 65 50 66 all: $(OUTPUT) $(OUTPUT).disasm51 all: $(OUTPUT) disasm 67 52 68 53 -include Makefile.depend … … 70 55 clean: 71 56 -rm -f $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend $(OBJECTS) 57 $(MAKE) -C libpci clean 72 58 73 59 depend: … … 75 61 76 62 $(OUTPUT): $(OBJECTS) $(LIBS) 63 $(MAKE) -C libpci 77 64 $(LD) -T $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map 78 65 79 disasm: $(OUTPUT).disasm 80 81 $(OUTPUT).disasm: $(OUTPUT) 82 $(OBJDUMP) -d $< >$@ 66 disasm: 67 $(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm 83 68 84 69 %.o: %.S … … 90 75 %.o: %.c 91 76 $(CC) $(DEFS) $(CFLAGS) -c $< -o $@ 77 78 libpci/libpci.a: 79 $(MAKE) -C libpci -
uspace/srv/pci/pci.c
rfd210de r64cbf94 1 #include <futex.h> 2 #include <assert.h> 1 /* 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 */ 3 9 4 #include "pci.h" 5 #include "pci_bus.h" 6 #include "pci_regs.h" 7 #include "pci_conf.h" 10 /** 11 * @addtogroup pci 12 * @{ 13 */ 8 14 9 #define NAME "PCI" 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> 10 22 11 LIST_INITIALIZE(devices_list); 12 LIST_INITIALIZE(buses_list); 13 LIST_INITIALIZE(drivers_list); 23 #include "libpci/pci.h" 14 24 15 static atomic_t pci_bus_futex = FUTEX_INITIALIZER; 25 #define PCI_CONF1 0xcf8 26 #define PCI_CONF1_SIZE 8 16 27 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); 28 #define NAME "PCI" 21 29 30 static struct pci_access *pacc; 22 31 23 void pci_bus_scan(pci_bus_t *bus)32 int main(int argc, char *argv[]) 24 33 { 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 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)); 57 } 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; 66 76 } 77 ipc_answer_0(callid, retval); 78 printf("%s: received call from %lX\n", NAME, 79 call.in_phone_hash); 67 80 } 68 69 if (dev->vendor_id == 0xFFFF) {70 pci_free_dev(dev); // free the auxiliary device structure71 }72 }73 81 74 /* 75 * Usage: pci_bus_futex must be down. 76 */ 77 static int pci_pass_dev(pci_drv_t *drv, pci_dev_t *dev) 78 { 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; 86 } 87 82 pci_cleanup(pacc); 88 83 return 0; 89 84 } 90 85 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 86 /** 87 * @} 88 */
Note:
See TracChangeset
for help on using the changeset viewer.