Index: uspace/drv/pciintel/pci.c
===================================================================
--- uspace/drv/pciintel/pci.c	(revision 663f41c465b5ccd70664cc4423f19a9fe2351eee)
+++ uspace/drv/pciintel/pci.c	(revision d93aafed6a897eaf52511eebeefccff890f54f5a)
@@ -65,5 +65,5 @@
 	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
 	
-	if (NULL == dev_data)
+	if (dev_data == NULL)
 		return NULL;
 	return &dev_data->hw_resources;
@@ -109,8 +109,9 @@
 	
 	bus_data = (pci_bus_data_t *) malloc(sizeof(pci_bus_data_t));
-	if (NULL != bus_data) {
+	if (bus_data != NULL) {
 		memset(bus_data, 0, sizeof(pci_bus_data_t));
 		fibril_mutex_initialize(&bus_data->conf_mutex);
 	}
+
 	return bus_data;
 }
@@ -123,5 +124,5 @@
 static void pci_conf_read(device_t *dev, int reg, uint8_t *buf, size_t len)
 {
-	assert(NULL != dev->parent);
+	assert(dev->parent != NULL);
 	
 	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
@@ -153,5 +154,5 @@
 static void pci_conf_write(device_t *dev, int reg, uint8_t *buf, size_t len)
 {
-	assert(NULL != dev->parent);
+	assert(dev->parent != NULL);
 	
 	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
@@ -224,5 +225,5 @@
 	
 	match_id = create_match_id();
-	if (NULL != match_id) {
+	if (match_id != NULL) {
 		asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
 		    dev_data->vendor_id, dev_data->device_id);
@@ -230,5 +231,6 @@
 		match_id->score = 90;
 		add_match_id(&dev->match_ids, match_id);
-	}	
+	}
+
 	/* TODO add more ids (with subsys ids, using class id etc.) */
 }
@@ -242,5 +244,5 @@
 	size_t count = hw_res_list->count;
 	
-	assert(NULL != hw_resources);
+	assert(hw_resources != NULL);
 	assert(count < PCI_MAX_HW_RES);
 	
@@ -275,5 +277,5 @@
 	bool io;
 	/* 64-bit wide address */
-	bool w64;
+	bool addrw64;
 	
 	/* Size of the io or memory range specified by the BAR */
@@ -287,12 +289,12 @@
 	io = (bool) (val & 1);
 	if (io) {
-		w64 = false;
+		addrw64 = false;
 	} else {
 		switch ((val >> 1) & 3) {
 		case 0:
-			w64 = false;
+			addrw64 = false;
 			break;
 		case 2:
-			w64 = true;
+			addrw64 = true;
 			break;
 		default:
@@ -312,5 +314,5 @@
 	range_size = pci_bar_mask_to_size(mask);
 	
-	if (w64) {
+	if (addrw64) {
 		range_addr = ((uint64_t)pci_conf_read_32(dev, addr + 4) << 32) |
 		    (val & 0xfffffff0);
@@ -319,5 +321,5 @@
 	}
 	
-	if (0 != range_addr) {
+	if (range_addr != 0) {
 		printf(NAME ": device %s : ", dev->name);
 		printf("address = %x", range_addr);
@@ -327,5 +329,5 @@
 	pci_add_range(dev, range_addr, range_size, io);
 	
-	if (w64)
+	if (addrw64)
 		return addr + 8;
 	
@@ -354,5 +356,5 @@
 {
 	uint8_t irq = pci_conf_read_8(dev, PCI_BRIDGE_INT_LINE);
-	if (0xff != irq)
+	if (irq != 0xff)
 		pci_add_interrupt(dev, irq);
 }
@@ -415,5 +417,5 @@
 			create_pci_match_ids(dev);
 			
-			if (EOK != child_device_register(dev, parent)) {
+			if (child_device_register(dev, parent) != EOK) {
 				pci_clean_resource_list(dev);
 				clean_match_ids(&dev->match_ids);
@@ -424,10 +426,10 @@
 			
 			if (header_type == PCI_HEADER_TYPE_BRIDGE ||
-			    header_type == PCI_HEADER_TYPE_CARDBUS ) {
+			    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)
+				if (child_bus > bus_num)
 					pci_bus_scan(parent, child_bus);
 			}
@@ -453,5 +455,5 @@
 	
 	pci_bus_data_t *bus_data = create_pci_bus_data();
-	if (NULL == bus_data) {
+	if (bus_data == NULL) {
 		printf(NAME ": pci_add_device allocation failed.\n");
 		return ENOMEM;
@@ -513,4 +515,79 @@
 }
 
+pci_dev_data_t *create_pci_dev_data(void)
+{
+	pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));
+	
+	if (res != NULL)
+		memset(res, 0, sizeof(pci_dev_data_t));
+	return res;
+}
+
+void init_pci_dev_data(pci_dev_data_t *dev_data, int bus, int dev, int fn)
+{
+	dev_data->bus = bus;
+	dev_data->dev = dev;
+	dev_data->fn = fn;
+}
+
+void delete_pci_dev_data(pci_dev_data_t *dev_data)
+{
+	if (dev_data != NULL) {
+		clean_hw_resource_list(&dev_data->hw_resources);
+		free(dev_data);
+	}
+}
+
+void create_pci_dev_name(device_t *dev)
+{
+	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
+	char *name = NULL;
+	
+	asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,
+	    dev_data->fn);
+	dev->name = name;
+}
+
+bool pci_alloc_resource_list(device_t *dev)
+{
+	pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
+	
+	dev_data->hw_resources.resources =
+	    (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
+	return dev_data->hw_resources.resources != NULL;
+}
+
+void pci_clean_resource_list(device_t *dev)
+{
+	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
+	
+	if (dev_data->hw_resources.resources != NULL) {
+		free(dev_data->hw_resources.resources);
+		dev_data->hw_resources.resources = NULL;
+	}
+}
+
+/** Read the base address registers (BARs) of the device and adds the addresses
+ * to its hw resource list.
+ *
+ * @param dev the pci device.
+ */
+void pci_read_bars(device_t *dev)
+{
+	/*
+	 * Position of the BAR in the PCI configuration address space of the
+	 * device.
+	 */
+	int addr = PCI_BASE_ADDR_0;
+	
+	while (addr <= PCI_BASE_ADDR_5)
+		addr = pci_read_bar(dev, addr);
+}
+
+size_t pci_bar_mask_to_size(uint32_t mask)
+{
+	return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
+}
+
 int main(int argc, char *argv[])
 {
