===== arch/ia64/sn/io/machvec/pci_dma.c 1.28 vs edited ===== --- 1.28/arch/ia64/sn/io/machvec/pci_dma.c Sun Mar 14 11:17:06 2004 +++ edited/arch/ia64/sn/io/machvec/pci_dma.c Fri Mar 19 16:26:33 2004 @@ -28,6 +28,28 @@ extern void * busnum_to_atedmamaps[]; /** + * pci_to_node - find the node a given PCI device is attached to + * @dev: PCI dev to query + * + * On sn2, physical address bits 38-48 are the nasid, so we can use it + * to get the node id. + */ +static short pci_to_node(struct pci_dev *dev) +{ + unsigned long nasid; + + /* FIXME: all PCI devices have at least one resource, right? */ + if (!dev->resource[0].start) { + printk("PCI device has no resources!\n"); + return 0; /* valid until node hot swap */ + } + + nasid = dev->resource[0].start & ~__IA64_UNCACHED_OFFSET; + nasid = nasid >> 38; + return nasid_to_cnodeid(nasid); +} + +/** * get_free_pciio_dmamap - find and allocate an ATE * @pci_bus: PCI bus to get an entry for * @@ -118,6 +140,7 @@ void * sn_pci_alloc_consistent(struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle) { + struct page *cpupage; void *cpuaddr; vertex_hdl_t vhdl; struct sn_device_sysdata *device_sysdata; @@ -130,13 +153,12 @@ device_sysdata = SN_DEVICE_SYSDATA(hwdev); vhdl = device_sysdata->vhdl; - /* - * Allocate the memory. - * FIXME: We should be doing alloc_pages_node for the node closest - * to the PCI device. - */ - if (!(cpuaddr = (void *)__get_free_pages(GFP_ATOMIC, get_order(size)))) + cpupage = alloc_pages_node(pci_to_node(hwdev), GFP_ATOMIC, + get_order(size)); + if (!cpupage) return NULL; + + cpuaddr = __va(page_to_phys(cpupage)); memset(cpuaddr, 0x0, size);