Index: uspace/drv/pciintel/pci.c
===================================================================
--- uspace/drv/pciintel/pci.c	(revision 472020fcce0d34f10b66ca0bd38c3b005abb9a4c)
+++ uspace/drv/pciintel/pci.c	(revision 663f41c465b5ccd70664cc4423f19a9fe2351eee)
@@ -58,19 +58,19 @@
 #define NAME "pciintel"
 
-#define CONF_ADDR(bus, dev, fn, reg)   ((1 << 31) | (bus << 16) | (dev << 11) | (fn << 8) | (reg & ~3))
-
-
-static hw_resource_list_t * pciintel_get_child_resources(device_t *dev)
-{
-	pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
-	if (NULL == dev_data) {
+#define CONF_ADDR(bus, dev, fn, reg) \
+	((1 << 31) | (bus << 16) | (dev << 11) | (fn << 8) | (reg & ~3))
+
+static hw_resource_list_t *pciintel_get_child_resources(device_t *dev)
+{
+	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
+	
+	if (NULL == dev_data)
 		return NULL;
-	}
 	return &dev_data->hw_resources;
 }
 
-static bool pciintel_enable_child_interrupt(device_t *dev) 
-{
-	// TODO
+static bool pciintel_enable_child_interrupt(device_t *dev)
+{
+	/* TODO */
 	
 	return false;
@@ -79,20 +79,17 @@
 static resource_iface_t pciintel_child_res_iface = {
 	&pciintel_get_child_resources,
-	&pciintel_enable_child_interrupt	
+	&pciintel_enable_child_interrupt
 };
 
 static device_ops_t pci_child_ops;
 
-
-static int pci_add_device(device_t *dev);
-
-/** The pci bus driver's standard operations.
- */
+static int pci_add_device(device_t *);
+
+/** The pci bus driver's standard operations. */
 static driver_ops_t pci_ops = {
 	.add_device = &pci_add_device
 };
 
-/** The pci bus driver structure. 
- */
+/** The pci bus driver structure. */
 static driver_t pci_driver = {
 	.name = NAME,
@@ -103,21 +100,23 @@
 	uint32_t conf_io_addr;
 	void *conf_data_port;
-	void *conf_addr_port;	
+	void *conf_addr_port;
 	fibril_mutex_t conf_mutex;
 } pci_bus_data_t;
 
-static inline pci_bus_data_t *create_pci_bus_data() 
-{
-	pci_bus_data_t *bus_data = (pci_bus_data_t *)malloc(sizeof(pci_bus_data_t));
-	if(NULL != bus_data) {
+static pci_bus_data_t *create_pci_bus_data(void)
+{
+	pci_bus_data_t *bus_data;
+	
+	bus_data = (pci_bus_data_t *) malloc(sizeof(pci_bus_data_t));
+	if (NULL != bus_data) {
 		memset(bus_data, 0, sizeof(pci_bus_data_t));
 		fibril_mutex_initialize(&bus_data->conf_mutex);
 	}
-	return bus_data;	
-}
-
-static inline void delete_pci_bus_data(pci_bus_data_t *bus_data) 
-{
-	free(bus_data);	
+	return bus_data;
+}
+
+static void delete_pci_bus_data(pci_bus_data_t *bus_data)
+{
+	free(bus_data);
 }
 
@@ -126,10 +125,11 @@
 	assert(NULL != dev->parent);
 	
-	pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
-	pci_bus_data_t *bus_data = (pci_bus_data_t *)dev->parent->driver_data;
+	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
+	pci_bus_data_t *bus_data = (pci_bus_data_t *) dev->parent->driver_data;
 	
 	fibril_mutex_lock(&bus_data->conf_mutex);
 	
-	uint32_t conf_addr =  CONF_ADDR(dev_data->bus, dev_data->dev, dev_data->fn, reg);
+	uint32_t conf_addr;
+	conf_addr = CONF_ADDR(dev_data->bus, dev_data->dev, dev_data->fn, reg);
 	void *addr = bus_data->conf_data_port + (reg & 3);
 	
@@ -137,16 +137,16 @@
 	
 	switch (len) {
-		case 1:
-			buf[0] = pio_read_8(addr);
-			break;
-		case 2:
-			((uint16_t *)buf)[0] = pio_read_16(addr);
-			break;
-		case 4:
-			((uint32_t *)buf)[0] = pio_read_32(addr);
-			break;
-	}
-	
-	fibril_mutex_unlock(&bus_data->conf_mutex);	
+	case 1:
+		buf[0] = pio_read_8(addr);
+		break;
+	case 2:
+		((uint16_t *) buf)[0] = pio_read_16(addr);
+		break;
+	case 4:
+		((uint32_t *) buf)[0] = pio_read_32(addr);
+		break;
+	}
+	
+	fibril_mutex_unlock(&bus_data->conf_mutex);
 }
 
@@ -155,10 +155,11 @@
 	assert(NULL != dev->parent);
 	
-	pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
-	pci_bus_data_t *bus_data = (pci_bus_data_t *)dev->parent->driver_data;
+	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
+	pci_bus_data_t *bus_data = (pci_bus_data_t *) dev->parent->driver_data;
 	
 	fibril_mutex_lock(&bus_data->conf_mutex);
 	
-	uint32_t conf_addr =  CONF_ADDR(dev_data->bus, dev_data->dev, dev_data->fn, reg);
+	uint32_t conf_addr;
+	conf_addr = CONF_ADDR(dev_data->bus, dev_data->dev, dev_data->fn, reg);
 	void *addr = bus_data->conf_data_port + (reg & 3);
 	
@@ -166,16 +167,16 @@
 	
 	switch (len) {
-		case 1:
-			pio_write_8(addr, buf[0]);
-			break;
-		case 2:
-			pio_write_16(addr, ((uint16_t *)buf)[0]);
-			break;
-		case 4:
-			pio_write_32(addr, ((uint32_t *)buf)[0]);
-			break;
-	}
-	
-	fibril_mutex_unlock(&bus_data->conf_mutex);	
+	case 1:
+		pio_write_8(addr, buf[0]);
+		break;
+	case 2:
+		pio_write_16(addr, ((uint16_t *) buf)[0]);
+		break;
+	case 4:
+		pio_write_32(addr, ((uint32_t *) buf)[0]);
+		break;
+	}
+	
+	fibril_mutex_unlock(&bus_data->conf_mutex);
 }
 
@@ -190,5 +191,5 @@
 {
 	uint16_t res;
-	pci_conf_read(dev, reg, (uint8_t *)&res, 2);
+	pci_conf_read(dev, reg, (uint8_t *) &res, 2);
 	return res;
 }
@@ -197,45 +198,47 @@
 {
 	uint32_t res;
-	pci_conf_read(dev, reg, (uint8_t *)&res, 4);
-	return res;	
-}
-
-void pci_conf_write_8(device_t *dev, int reg, uint8_t val) 
-{
-	pci_conf_write(dev, reg, (uint8_t *)&val, 1);	
-}
-
-void pci_conf_write_16(device_t *dev, int reg, uint16_t val) 
-{
-	pci_conf_write(dev, reg, (uint8_t *)&val, 2);	
-}
-
-void pci_conf_write_32(device_t *dev, int reg, uint32_t val) 
-{
-	pci_conf_write(dev, reg, (uint8_t *)&val, 4);	
-}
-
+	pci_conf_read(dev, reg, (uint8_t *) &res, 4);
+	return res;
+}
+
+void pci_conf_write_8(device_t *dev, int reg, uint8_t val)
+{
+	pci_conf_write(dev, reg, (uint8_t *) &val, 1);
+}
+
+void pci_conf_write_16(device_t *dev, int reg, uint16_t val)
+{
+	pci_conf_write(dev, reg, (uint8_t *) &val, 2);
+}
+
+void pci_conf_write_32(device_t *dev, int reg, uint32_t val)
+{
+	pci_conf_write(dev, reg, (uint8_t *) &val, 4);
+}
 
 void create_pci_match_ids(device_t *dev)
 {
-	pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
-	match_id_t *match_id = NULL;	
-	char *match_id_str;	
+	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
+	match_id_t *match_id = NULL;
+	char *match_id_str;
+	
 	match_id = create_match_id();
 	if (NULL != match_id) {
-		asprintf(&match_id_str, "pci/ven=%04x&dev=%04x", dev_data->vendor_id, dev_data->device_id);
+		asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
+		    dev_data->vendor_id, dev_data->device_id);
 		match_id->id = match_id_str;
 		match_id->score = 90;
 		add_match_id(&dev->match_ids, match_id);
 	}	
-	// TODO add more ids (with subsys ids, using class id etc.)
-}
-
-void pci_add_range(device_t *dev, uint64_t range_addr, size_t range_size, bool io)
-{
-	pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
+	/* TODO add more ids (with subsys ids, using class id etc.) */
+}
+
+void
+pci_add_range(device_t *dev, uint64_t range_addr, size_t range_size, bool io)
+{
+	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
 	hw_resource_list_t *hw_res_list = &dev_data->hw_resources;
 	hw_resource_t *hw_resources =  hw_res_list->resources;
-	size_t count = hw_res_list->count;	
+	size_t count = hw_res_list->count;
 	
 	assert(NULL != hw_resources);
@@ -245,43 +248,42 @@
 		hw_resources[count].type = IO_RANGE;
 		hw_resources[count].res.io_range.address = range_addr;
-		hw_resources[count].res.io_range.size = range_size;	
-		hw_resources[count].res.io_range.endianness = LITTLE_ENDIAN;	
+		hw_resources[count].res.io_range.size = range_size;
+		hw_resources[count].res.io_range.endianness = LITTLE_ENDIAN;
 	} else {
 		hw_resources[count].type = MEM_RANGE;
 		hw_resources[count].res.mem_range.address = range_addr;
-		hw_resources[count].res.mem_range.size = range_size;	
+		hw_resources[count].res.mem_range.size = range_size;
 		hw_resources[count].res.mem_range.endianness = LITTLE_ENDIAN;
 	}
 	
-	hw_res_list->count++;	
-}
-
-
-/** Read the base address register (BAR) of the device 
- *  and if it contains valid address add it to the devices hw resource list.
- * 
- * @param dev the pci device.
- * @param addr the address of the BAR in the PCI configuration address space of the device.
- * 
- * @return the addr the address of the BAR which should be read next.
+	hw_res_list->count++;
+}
+
+/** Read the base address register (BAR) of the device and if it contains valid
+ * address add it to the devices hw resource list.
+ *
+ * @param dev	The pci device.
+ * @param addr	The address of the BAR in the PCI configuration address space of
+ *		the device.
+ * @return	The addr the address of the BAR which should be read next.
  */
-int pci_read_bar(device_t *dev, int addr) 
+int pci_read_bar(device_t *dev, int addr)
 {	
-	// value of the BAR
+	/* Value of the BAR */
 	uint32_t val, mask;
-	// IO space address
+	/* IO space address */
 	bool io;
-	// 64-bit wide address
+	/* 64-bit wide address */
 	bool w64;
 	
-	// size of the io or memory range specified by the BAR
+	/* Size of the io or memory range specified by the BAR */
 	size_t range_size;
-	// beginning of the io or memory range specified by the BAR
+	/* Beginning of the io or memory range specified by the BAR */
 	uint64_t range_addr;
 	
-	// get the value of the BAR
+	/* Get the value of the BAR. */
 	val = pci_conf_read_32(dev, addr);
 	
-	io = (bool)(val & 1);
+	io = (bool) (val & 1);
 	if (io) {
 		w64 = false;
@@ -295,27 +297,29 @@
 			break;
 		default:
-			// reserved, go to the next BAR
-			return addr + 4;							
+			/* reserved, go to the next BAR */
+			return addr + 4;
 		}
 	}
 	
-	// get the address mask
+	/* Get the address mask. */
 	pci_conf_write_32(dev, addr, 0xffffffff);
-	mask = pci_conf_read_32(dev, addr);	
-	
-	// restore the original value
+	mask = pci_conf_read_32(dev, addr);
+	
+	/* Restore the original value. */
 	pci_conf_write_32(dev, addr, val);
-	val = pci_conf_read_32(dev, addr);	
+	val = pci_conf_read_32(dev, addr);
 	
 	range_size = pci_bar_mask_to_size(mask);
 	
 	if (w64) {
-		range_addr = ((uint64_t)pci_conf_read_32(dev, addr + 4) << 32) | (val & 0xfffffff0);	
+		range_addr = ((uint64_t)pci_conf_read_32(dev, addr + 4) << 32) |
+		    (val & 0xfffffff0);
 	} else {
 		range_addr = (val & 0xfffffff0);
-	}	
+	}
+	
 	if (0 != range_addr) {
 		printf(NAME ": device %s : ", dev->name);
-		printf("address = %x", range_addr);		
+		printf("address = %x", range_addr);
 		printf(", size = %x\n", range_size);
 	}
@@ -323,16 +327,16 @@
 	pci_add_range(dev, range_addr, range_size, io);
 	
-	if (w64) {
+	if (w64)
 		return addr + 8;
-	}
-	return addr + 4;	
+	
+	return addr + 4;
 }
 
 void pci_add_interrupt(device_t *dev, int irq)
 {
-	pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
+	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
 	hw_resource_list_t *hw_res_list = &dev_data->hw_resources;
-	hw_resource_t *hw_resources =  hw_res_list->resources;
-	size_t count = hw_res_list->count;	
+	hw_resource_t *hw_resources = hw_res_list->resources;
+	size_t count = hw_res_list->count;
 	
 	assert(NULL != hw_resources);
@@ -342,6 +346,5 @@
 	hw_resources[count].res.interrupt.irq = irq;
 	
-	hw_res_list->count++;		
-	
+	hw_res_list->count++;
 	
 	printf(NAME ": device %s uses irq %x.\n", dev->name, irq);
@@ -351,13 +354,12 @@
 {
 	uint8_t irq = pci_conf_read_8(dev, PCI_BRIDGE_INT_LINE);
-	if (0xff != irq) {
+	if (0xff != irq)
 		pci_add_interrupt(dev, irq);
-	}	
 }
 
 /** Enumerate (recursively) and register the devices connected to a pci bus.
- * 
- * @param parent the host-to-pci bridge device.
- * @param bus_num the bus number. 
+ *
+ * @param parent	The host-to-pci bridge device.
+ * @param bus_num	The bus number.
  */
 void pci_bus_scan(device_t *parent, int bus_num) 
@@ -377,18 +379,26 @@
 		for (fnum = 0; multi && fnum < 8; fnum++) {
 			init_pci_dev_data(dev_data, bus_num, dnum, fnum);
-			dev_data->vendor_id = pci_conf_read_16(dev, PCI_VENDOR_ID);
-			dev_data->device_id = pci_conf_read_16(dev, PCI_DEVICE_ID);
-			if (dev_data->vendor_id == 0xffff) { // device is not present, go on scanning the bus
-				if (fnum == 0) {
+			dev_data->vendor_id = pci_conf_read_16(dev,
+			    PCI_VENDOR_ID);
+			dev_data->device_id = pci_conf_read_16(dev,
+			    PCI_DEVICE_ID);
+			if (dev_data->vendor_id == 0xffff) {
+				/*
+				 * The device is not present, go on scanning the
+				 * bus.
+				 */
+				if (fnum == 0)
 					break;
-				} else {
-					continue;  
-				}
+				else
+					continue;
 			}
+			
 			header_type = pci_conf_read_8(dev, PCI_HEADER_TYPE);
 			if (fnum == 0) {
-				 multi = header_type >> 7;  // is the device multifunction?
+				/* Is the device multifunction? */
+				multi = header_type >> 7;
 			}
-			header_type = header_type & 0x7F; // clear the multifunction bit
+			/* Clear the multifunction bit. */
+			header_type = header_type & 0x7F;
 			
 			create_pci_dev_name(dev);
@@ -398,29 +408,31 @@
 			pci_read_interrupt(dev);
 			
-			dev->ops = &pci_child_ops;			
-			
-			printf(NAME ": adding new child device %s.\n", dev->name);
+			dev->ops = &pci_child_ops;
+			
+			printf(NAME ": adding new child device %s.\n",
+			    dev->name);
 			
 			create_pci_match_ids(dev);
 			
-			if (EOK != child_device_register(dev, parent)) {				
-				pci_clean_resource_list(dev);				
+			if (EOK != child_device_register(dev, parent)) {
+				pci_clean_resource_list(dev);
 				clean_match_ids(&dev->match_ids);
-				free((char *)dev->name);
+				free((char *) dev->name);
 				dev->name = NULL;
 				continue;
 			}
 			
-			//printf(NAME ": new device %s was successfully registered by device manager.\n", dev->name);
-			
-			if (header_type == PCI_HEADER_TYPE_BRIDGE || header_type == PCI_HEADER_TYPE_CARDBUS ) {
-				child_bus = pci_conf_read_8(dev, PCI_BRIDGE_SEC_BUS_NUM);
-				printf(NAME ": device is pci-to-pci bridge, secondary bus number = %d.\n", bus_num);
-				if(child_bus > bus_num) {			
-					pci_bus_scan(parent, child_bus);	
-				}					
+			if (header_type == PCI_HEADER_TYPE_BRIDGE ||
+			    header_type == PCI_HEADER_TYPE_CARDBUS ) {
+				child_bus = pci_conf_read_8(dev,
+				    PCI_BRIDGE_SEC_BUS_NUM);
+				printf(NAME ": device is pci-to-pci bridge, "
+				    "secondary bus number = %d.\n", bus_num);
+				if(child_bus > bus_num)
+					pci_bus_scan(parent, child_bus);
 			}
 			
-			dev = create_device();  // alloc new aux. dev. structure
+			/* Alloc new aux. dev. structure. */
+			dev = create_device();
 			dev_data = create_pci_dev_data();
 			dev->driver_data = dev_data;
@@ -431,6 +443,7 @@
 	if (dev_data->vendor_id == 0xffff) {
 		delete_device(dev);
-		delete_pci_dev_data(dev_data);  // free the auxiliary device structure
-	}		
+		/* Free the auxiliary device structure. */
+		delete_pci_dev_data(dev_data);
+	}
 }
 
@@ -443,9 +456,11 @@
 		printf(NAME ": pci_add_device allocation failed.\n");
 		return ENOMEM;
-	}	
-	
-	dev->parent_phone = devman_parent_device_connect(dev->handle,  IPC_FLAG_BLOCKING);
-	if (dev->parent_phone <= 0) {
-		printf(NAME ": pci_add_device failed to connect to the parent's driver.\n");
+	}
+	
+	dev->parent_phone = devman_parent_device_connect(dev->handle,
+	    IPC_FLAG_BLOCKING);
+	if (dev->parent_phone < 0) {
+		printf(NAME ": pci_add_device failed to connect to the "
+		    "parent's driver.\n");
 		delete_pci_bus_data(bus_data);
 		return EPARTY;	/* FIXME: use another EC */
@@ -455,5 +470,6 @@
 	
 	if (!get_hw_resources(dev->parent_phone, &hw_resources)) {
-		printf(NAME ": pci_add_device failed to get hw resources for the device.\n");
+		printf(NAME ": pci_add_device failed to get hw resources for "
+		    "the device.\n");
 		delete_pci_bus_data(bus_data);
 		ipc_hangup(dev->parent_phone);
@@ -461,5 +477,6 @@
 	}	
 	
-	printf(NAME ": conf_addr = %x.\n", hw_resources.resources[0].res.io_range.address);	
+	printf(NAME ": conf_addr = %x.\n",
+	    hw_resources.resources[0].res.io_range.address);
 	
 	assert(hw_resources.count > 0);
@@ -467,18 +484,20 @@
 	assert(hw_resources.resources[0].res.io_range.size == 8);
 	
-	bus_data->conf_io_addr = (uint32_t)hw_resources.resources[0].res.io_range.address;
-	
-	if (pio_enable((void *)bus_data->conf_io_addr, 8, &bus_data->conf_addr_port)) {
+	bus_data->conf_io_addr =
+	    (uint32_t) hw_resources.resources[0].res.io_range.address;
+	
+	if (pio_enable((void *)bus_data->conf_io_addr, 8,
+	    &bus_data->conf_addr_port)) {
 		printf(NAME ": failed to enable configuration ports.\n");
 		delete_pci_bus_data(bus_data);
 		ipc_hangup(dev->parent_phone);
 		clean_hw_resource_list(&hw_resources);
-		return EADDRNOTAVAIL;					
-	}
-	bus_data->conf_data_port = (char *)bus_data->conf_addr_port + 4;
+		return EADDRNOTAVAIL;
+	}
+	bus_data->conf_data_port = (char *) bus_data->conf_addr_port + 4;
 	
 	dev->driver_data = bus_data;
 	
-	// enumerate child devices
+	/* Enumerate child devices. */
 	printf(NAME ": scanning the bus\n");
 	pci_bus_scan(dev, 0);
@@ -489,5 +508,5 @@
 }
 
-static void pciintel_init() 
+static void pciintel_init(void)
 {
 	pci_child_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_child_res_iface;
