Lines Matching +full:charge +full:- +full:ctrl +full:- +full:value

4  * Copyright (C) 2002-2005 Dave Jones.
9 * Permission is hereby granted, free of charge, to any person obtaining a
28 * - Allocate more than order 0 pages to avoid too much linear map splitting.
37 #include <linux/dma-mapping.h>
57 * Generic routines for handling agp_memory structures -
67 clear_bit(key, agp_bridge->key_list); in agp_free_key()
76 bit = find_first_zero_bit(agp_bridge->key_list, MAXKEY); in agp_get_key()
78 set_bit(bit, agp_bridge->key_list); in agp_get_key()
81 return -1; in agp_get_key()
92 mem->pages = kvmalloc(size, GFP_KERNEL); in agp_alloc_page_array()
108 new->key = agp_get_key(); in agp_create_user_memory()
110 if (new->key < 0) { in agp_create_user_memory()
117 if (new->pages == NULL) { in agp_create_user_memory()
118 agp_free_key(new->key); in agp_create_user_memory()
122 new->num_scratch_pages = 0; in agp_create_user_memory()
134 new->key = agp_get_key(); in agp_create_memory()
136 if (new->key < 0) { in agp_create_memory()
143 if (new->pages == NULL) { in agp_create_memory()
144 agp_free_key(new->key); in agp_create_memory()
148 new->num_scratch_pages = scratch_pages; in agp_create_memory()
149 new->type = AGP_NORMAL_MEMORY; in agp_create_memory()
155 * agp_free_memory - free memory associated with an agp_memory pointer.
169 if (curr->is_bound) in agp_free_memory()
172 if (curr->type >= AGP_USER_TYPES) { in agp_free_memory()
177 if (curr->type != 0) { in agp_free_memory()
178 curr->bridge->driver->free_by_type(curr); in agp_free_memory()
181 if (curr->page_count != 0) { in agp_free_memory()
182 if (curr->bridge->driver->agp_destroy_pages) { in agp_free_memory()
183 curr->bridge->driver->agp_destroy_pages(curr); in agp_free_memory()
186 for (i = 0; i < curr->page_count; i++) { in agp_free_memory()
187 curr->bridge->driver->agp_destroy_page( in agp_free_memory()
188 curr->pages[i], in agp_free_memory()
191 for (i = 0; i < curr->page_count; i++) { in agp_free_memory()
192 curr->bridge->driver->agp_destroy_page( in agp_free_memory()
193 curr->pages[i], in agp_free_memory()
198 agp_free_key(curr->key); in agp_free_memory()
207 * agp_allocate_memory - allocate a group of pages of a certain type.
229 cur_memory = atomic_read(&bridge->current_memory_agp); in agp_allocate_memory()
230 if ((cur_memory + page_count > bridge->max_memory_agp) || in agp_allocate_memory()
237 new->bridge = bridge; in agp_allocate_memory()
242 new = bridge->driver->alloc_by_type(page_count, type); in agp_allocate_memory()
244 new->bridge = bridge; in agp_allocate_memory()
248 scratch_pages = (page_count + ENTRIES_PER_PAGE - 1) / ENTRIES_PER_PAGE; in agp_allocate_memory()
255 if (bridge->driver->agp_alloc_pages) { in agp_allocate_memory()
256 if (bridge->driver->agp_alloc_pages(bridge, new, page_count)) { in agp_allocate_memory()
260 new->bridge = bridge; in agp_allocate_memory()
265 struct page *page = bridge->driver->agp_alloc_page(bridge); in agp_allocate_memory()
271 new->pages[i] = page; in agp_allocate_memory()
272 new->page_count++; in agp_allocate_memory()
274 new->bridge = bridge; in agp_allocate_memory()
281 /* End - Generic routines for handling agp_memory structures */
289 temp = agp_bridge->current_size; in agp_return_size()
291 switch (agp_bridge->driver->size_type) { in agp_return_size()
293 current_size = A_SIZE_8(temp)->size; in agp_return_size()
296 current_size = A_SIZE_16(temp)->size; in agp_return_size()
299 current_size = A_SIZE_32(temp)->size; in agp_return_size()
302 current_size = A_SIZE_LVL2(temp)->size; in agp_return_size()
305 current_size = A_SIZE_FIX(temp)->size; in agp_return_size()
312 current_size -= (agp_memory_reserved / (1024*1024)); in agp_return_size()
324 temp = agp_bridge->current_size; in agp_num_entries()
326 switch (agp_bridge->driver->size_type) { in agp_num_entries()
328 num_entries = A_SIZE_8(temp)->num_entries; in agp_num_entries()
331 num_entries = A_SIZE_16(temp)->num_entries; in agp_num_entries()
334 num_entries = A_SIZE_32(temp)->num_entries; in agp_num_entries()
337 num_entries = A_SIZE_LVL2(temp)->num_entries; in agp_num_entries()
340 num_entries = A_SIZE_FIX(temp)->num_entries; in agp_num_entries()
347 num_entries -= agp_memory_reserved>>PAGE_SHIFT; in agp_num_entries()
356 * agp_copy_info - copy bridge state information
368 info->chipset = NOT_SUPPORTED; in agp_copy_info()
369 return -EIO; in agp_copy_info()
372 info->version.major = bridge->version->major; in agp_copy_info()
373 info->version.minor = bridge->version->minor; in agp_copy_info()
374 info->chipset = SUPPORTED; in agp_copy_info()
375 info->device = bridge->dev; in agp_copy_info()
376 if (bridge->mode & AGPSTAT_MODE_3_0) in agp_copy_info()
377 info->mode = bridge->mode & ~AGP3_RESERVED_MASK; in agp_copy_info()
379 info->mode = bridge->mode & ~AGP2_RESERVED_MASK; in agp_copy_info()
380 info->aper_base = bridge->gart_bus_addr; in agp_copy_info()
381 info->aper_size = agp_return_size(); in agp_copy_info()
382 info->max_memory = bridge->max_memory_agp; in agp_copy_info()
383 info->current_memory = atomic_read(&bridge->current_memory_agp); in agp_copy_info()
384 info->cant_use_aperture = bridge->driver->cant_use_aperture; in agp_copy_info()
385 info->vm_ops = bridge->vm_ops; in agp_copy_info()
386 info->page_mask = ~0UL; in agp_copy_info()
391 /* End - Routine to copy over information structure */
394 * Routines for handling swapping of agp_memory into the GATT -
400 * agp_bind_memory - Bind an agp_memory structure into the GATT.
405 * It returns -EINVAL if the pointer == NULL.
406 * It returns -EBUSY if the area of the table requested is already in use.
413 return -EINVAL; in agp_bind_memory()
415 if (curr->is_bound) { in agp_bind_memory()
417 return -EINVAL; in agp_bind_memory()
419 if (!curr->is_flushed) { in agp_bind_memory()
420 curr->bridge->driver->cache_flush(); in agp_bind_memory()
421 curr->is_flushed = true; in agp_bind_memory()
424 ret_val = curr->bridge->driver->insert_memory(curr, pg_start, curr->type); in agp_bind_memory()
429 curr->is_bound = true; in agp_bind_memory()
430 curr->pg_start = pg_start; in agp_bind_memory()
431 spin_lock(&agp_bridge->mapped_lock); in agp_bind_memory()
432 list_add(&curr->mapped_list, &agp_bridge->mapped_list); in agp_bind_memory()
433 spin_unlock(&agp_bridge->mapped_lock); in agp_bind_memory()
441 * agp_unbind_memory - Removes an agp_memory structure from the GATT
445 * It returns -EINVAL if this piece of agp_memory is not currently bound to
453 return -EINVAL; in agp_unbind_memory()
455 if (!curr->is_bound) { in agp_unbind_memory()
457 return -EINVAL; in agp_unbind_memory()
460 ret_val = curr->bridge->driver->remove_memory(curr, curr->pg_start, curr->type); in agp_unbind_memory()
465 curr->is_bound = false; in agp_unbind_memory()
466 curr->pg_start = 0; in agp_unbind_memory()
467 spin_lock(&curr->bridge->mapped_lock); in agp_unbind_memory()
468 list_del(&curr->mapped_list); in agp_unbind_memory()
469 spin_unlock(&curr->bridge->mapped_lock); in agp_unbind_memory()
475 /* End - Routines for handling swapping of agp_memory into the GATT */
478 /* Generic Agp routines - Start */
518 printk(KERN_INFO PFX "%s tried to set rate=x0. Setting to x1 mode.\n", current->comm); in agp_v2_parse_one()
561 if (agp_bridge->flags & AGP_ERRATA_FASTWRITES) in agp_v2_parse_one()
564 if (agp_bridge->flags & AGP_ERRATA_SBA) in agp_v2_parse_one()
567 if (agp_bridge->flags & AGP_ERRATA_1X) { in agp_v2_parse_one()
596 printk(KERN_INFO PFX "%s tried to set rate=x0. Setting to AGP3 x4 mode.\n", current->comm); in agp_v3_parse_one()
600 …printk(KERN_INFO PFX "%s tried to set rate=x%d. Setting to AGP3 x8 mode.\n", current->comm, tmp * … in agp_v3_parse_one()
604 /* ARQSZ - Set the value to the maximum one. in agp_v3_parse_one()
626 * AGP2.x 4x -> AGP3.0 4x. in agp_v3_parse_one()
630 current->comm, *requested_mode); in agp_v3_parse_one()
638 * Convert AGP 1x,2x,4x -> AGP 3.0 4x. in agp_v3_parse_one()
641 current->comm, *requested_mode); in agp_v3_parse_one()
650 printk(KERN_INFO PFX "%s requested AGPx8 but bridge not capable.\n", current->comm); in agp_v3_parse_one()
656 printk(KERN_INFO PFX "%s requested AGPx8 but graphic card not capable.\n", current->comm); in agp_v3_parse_one()
699 if (agp_bridge->flags & AGP_ERRATA_FASTWRITES) in agp_v3_parse_one()
702 if (agp_bridge->flags & AGP_ERRATA_SBA) in agp_v3_parse_one()
705 if (agp_bridge->flags & AGP_ERRATA_1X) { in agp_v3_parse_one()
713 * agp_collect_device_status - determine correct agp_cmd from various agp_stat's
756 if (agp_bridge->mode & AGPSTAT_MODE_3_0) in agp_collect_device_status()
781 dev_info(&device->dev, "putting AGP V%d device into %dx mode\n", in agp_device_command()
794 if (bridge->major_version != 0) in get_agp_version()
797 pci_read_config_dword(bridge->dev, bridge->capndx, &ncapid); in get_agp_version()
798 bridge->major_version = (ncapid >> AGP_MAJOR_VERSION_SHIFT) & 0xf; in get_agp_version()
799 bridge->minor_version = (ncapid >> AGP_MINOR_VERSION_SHIFT) & 0xf; in get_agp_version()
810 dev_info(&agp_bridge->dev->dev, "AGP %d.%d bridge\n", in agp_generic_enable()
811 agp_bridge->major_version, agp_bridge->minor_version); in agp_generic_enable()
813 pci_read_config_dword(agp_bridge->dev, in agp_generic_enable()
814 agp_bridge->capndx + PCI_AGP_STATUS, &bridge_agpstat); in agp_generic_enable()
824 if (bridge->major_version >= 3) { in agp_generic_enable()
825 if (bridge->mode & AGPSTAT_MODE_3_0) { in agp_generic_enable()
827 if (bridge->minor_version >= 5) in agp_generic_enable()
834 pci_read_config_dword(bridge->dev, in agp_generic_enable()
835 bridge->capndx+AGPCTRL, &temp); in agp_generic_enable()
837 pci_write_config_dword(bridge->dev, in agp_generic_enable()
838 bridge->capndx+AGPCTRL, temp); in agp_generic_enable()
840 dev_info(&bridge->dev->dev, "bridge is in legacy mode, falling back to 2.x\n"); in agp_generic_enable()
861 if (bridge->driver->size_type == LVL2_APER_SIZE) in agp_generic_create_gatt_table()
862 return -EINVAL; in agp_generic_create_gatt_table()
865 i = bridge->aperture_size_idx; in agp_generic_create_gatt_table()
866 temp = bridge->current_size; in agp_generic_create_gatt_table()
869 if (bridge->driver->size_type != FIXED_APER_SIZE) { in agp_generic_create_gatt_table()
871 switch (bridge->driver->size_type) { in agp_generic_create_gatt_table()
874 A_SIZE_8(temp)->page_order; in agp_generic_create_gatt_table()
876 A_SIZE_8(temp)->num_entries; in agp_generic_create_gatt_table()
879 page_order = A_SIZE_16(temp)->page_order; in agp_generic_create_gatt_table()
880 num_entries = A_SIZE_16(temp)->num_entries; in agp_generic_create_gatt_table()
883 page_order = A_SIZE_32(temp)->page_order; in agp_generic_create_gatt_table()
884 num_entries = A_SIZE_32(temp)->num_entries; in agp_generic_create_gatt_table()
898 switch (bridge->driver->size_type) { in agp_generic_create_gatt_table()
900 bridge->current_size = A_IDX8(bridge); in agp_generic_create_gatt_table()
903 bridge->current_size = A_IDX16(bridge); in agp_generic_create_gatt_table()
906 bridge->current_size = A_IDX32(bridge); in agp_generic_create_gatt_table()
914 temp = bridge->current_size; in agp_generic_create_gatt_table()
916 bridge->aperture_size_idx = i; in agp_generic_create_gatt_table()
918 } while (!table && (i < bridge->driver->num_aperture_sizes)); in agp_generic_create_gatt_table()
920 page_order = ((struct aper_size_info_fixed *) temp)->page_order; in agp_generic_create_gatt_table()
921 num_entries = ((struct aper_size_info_fixed *) temp)->num_entries; in agp_generic_create_gatt_table()
926 return -ENOMEM; in agp_generic_create_gatt_table()
928 table_end = table + ((PAGE_SIZE * (1 << page_order)) - 1); in agp_generic_create_gatt_table()
933 bridge->gatt_table_real = (u32 *) table; in agp_generic_create_gatt_table()
936 bridge->driver->cache_flush(); in agp_generic_create_gatt_table()
941 bridge->gatt_table = (u32 __iomem *)table; in agp_generic_create_gatt_table()
943 bridge->gatt_table = ioremap(virt_to_phys(table), in agp_generic_create_gatt_table()
945 bridge->driver->cache_flush(); in agp_generic_create_gatt_table()
948 if (bridge->gatt_table == NULL) { in agp_generic_create_gatt_table()
954 return -ENOMEM; in agp_generic_create_gatt_table()
956 bridge->gatt_bus_addr = virt_to_phys(bridge->gatt_table_real); in agp_generic_create_gatt_table()
960 writel(bridge->scratch_page, bridge->gatt_table+i); in agp_generic_create_gatt_table()
961 readl(bridge->gatt_table+i); /* PCI Posting. */ in agp_generic_create_gatt_table()
975 temp = bridge->current_size; in agp_generic_free_gatt_table()
977 switch (bridge->driver->size_type) { in agp_generic_free_gatt_table()
979 page_order = A_SIZE_8(temp)->page_order; in agp_generic_free_gatt_table()
982 page_order = A_SIZE_16(temp)->page_order; in agp_generic_free_gatt_table()
985 page_order = A_SIZE_32(temp)->page_order; in agp_generic_free_gatt_table()
988 page_order = A_SIZE_FIX(temp)->page_order; in agp_generic_free_gatt_table()
992 return -EINVAL; in agp_generic_free_gatt_table()
1003 set_memory_wb((unsigned long)bridge->gatt_table, 1 << page_order); in agp_generic_free_gatt_table()
1005 iounmap(bridge->gatt_table); in agp_generic_free_gatt_table()
1007 table = (char *) bridge->gatt_table_real; in agp_generic_free_gatt_table()
1008 table_end = table + ((PAGE_SIZE * (1 << page_order)) - 1); in agp_generic_free_gatt_table()
1013 free_gatt_pages(bridge->gatt_table_real, page_order); in agp_generic_free_gatt_table()
1016 bridge->gatt_table = NULL; in agp_generic_free_gatt_table()
1017 bridge->gatt_table_real = NULL; in agp_generic_free_gatt_table()
1018 bridge->gatt_bus_addr = 0; in agp_generic_free_gatt_table()
1034 bridge = mem->bridge; in agp_generic_insert_memory()
1036 return -EINVAL; in agp_generic_insert_memory()
1038 if (mem->page_count == 0) in agp_generic_insert_memory()
1041 temp = bridge->current_size; in agp_generic_insert_memory()
1043 switch (bridge->driver->size_type) { in agp_generic_insert_memory()
1045 num_entries = A_SIZE_8(temp)->num_entries; in agp_generic_insert_memory()
1048 num_entries = A_SIZE_16(temp)->num_entries; in agp_generic_insert_memory()
1051 num_entries = A_SIZE_32(temp)->num_entries; in agp_generic_insert_memory()
1054 num_entries = A_SIZE_FIX(temp)->num_entries; in agp_generic_insert_memory()
1058 return -EINVAL; in agp_generic_insert_memory()
1064 num_entries -= agp_memory_reserved/PAGE_SIZE; in agp_generic_insert_memory()
1067 if (type != mem->type) in agp_generic_insert_memory()
1068 return -EINVAL; in agp_generic_insert_memory()
1070 mask_type = bridge->driver->agp_type_to_mask_type(bridge, type); in agp_generic_insert_memory()
1073 return -EINVAL; in agp_generic_insert_memory()
1076 if (((pg_start + mem->page_count) > num_entries) || in agp_generic_insert_memory()
1077 ((pg_start + mem->page_count) < pg_start)) in agp_generic_insert_memory()
1078 return -EINVAL; in agp_generic_insert_memory()
1082 while (j < (pg_start + mem->page_count)) { in agp_generic_insert_memory()
1083 if (!PGE_EMPTY(bridge, readl(bridge->gatt_table+j))) in agp_generic_insert_memory()
1084 return -EBUSY; in agp_generic_insert_memory()
1088 if (!mem->is_flushed) { in agp_generic_insert_memory()
1089 bridge->driver->cache_flush(); in agp_generic_insert_memory()
1090 mem->is_flushed = true; in agp_generic_insert_memory()
1093 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { in agp_generic_insert_memory()
1094 writel(bridge->driver->mask_memory(bridge, in agp_generic_insert_memory()
1095 page_to_phys(mem->pages[i]), in agp_generic_insert_memory()
1097 bridge->gatt_table+j); in agp_generic_insert_memory()
1099 readl(bridge->gatt_table+j-1); /* PCI Posting. */ in agp_generic_insert_memory()
1101 bridge->driver->tlb_flush(mem); in agp_generic_insert_memory()
1113 bridge = mem->bridge; in agp_generic_remove_memory()
1115 return -EINVAL; in agp_generic_remove_memory()
1117 if (mem->page_count == 0) in agp_generic_remove_memory()
1120 if (type != mem->type) in agp_generic_remove_memory()
1121 return -EINVAL; in agp_generic_remove_memory()
1124 if (((pg_start + mem->page_count) > num_entries) || in agp_generic_remove_memory()
1125 ((pg_start + mem->page_count) < pg_start)) in agp_generic_remove_memory()
1126 return -EINVAL; in agp_generic_remove_memory()
1128 mask_type = bridge->driver->agp_type_to_mask_type(bridge, type); in agp_generic_remove_memory()
1131 return -EINVAL; in agp_generic_remove_memory()
1135 for (i = pg_start; i < (mem->page_count + pg_start); i++) { in agp_generic_remove_memory()
1136 writel(bridge->scratch_page, bridge->gatt_table+i); in agp_generic_remove_memory()
1138 readl(bridge->gatt_table+i-1); /* PCI Posting. */ in agp_generic_remove_memory()
1140 bridge->driver->tlb_flush(mem); in agp_generic_remove_memory()
1154 agp_free_key(curr->key); in agp_generic_free_by_type()
1165 pages = (page_count + ENTRIES_PER_PAGE - 1) / ENTRIES_PER_PAGE; in agp_generic_alloc_user()
1171 new->pages[i] = NULL; in agp_generic_alloc_user()
1172 new->page_count = 0; in agp_generic_alloc_user()
1173 new->type = type; in agp_generic_alloc_user()
1174 new->num_scratch_pages = pages; in agp_generic_alloc_user()
1181 * Basic Page Allocation Routines -
1183 * memory. They also handle incrementing the current_memory_agp value, Which is checked
1184 * against a maximum value.
1190 int i, ret = -ENOMEM; in agp_generic_alloc_pages()
1202 atomic_inc(&agp_bridge->current_memory_agp); in agp_generic_alloc_pages()
1204 mem->pages[i] = page; in agp_generic_alloc_pages()
1205 mem->page_count++; in agp_generic_alloc_pages()
1209 set_pages_array_uc(mem->pages, num_pages); in agp_generic_alloc_pages()
1228 atomic_inc(&agp_bridge->current_memory_agp); in agp_generic_alloc_page()
1242 set_pages_array_wb(mem->pages, mem->page_count); in agp_generic_destroy_pages()
1245 for (i = 0; i < mem->page_count; i++) { in agp_generic_destroy_pages()
1246 page = mem->pages[i]; in agp_generic_destroy_pages()
1253 atomic_dec(&agp_bridge->current_memory_agp); in agp_generic_destroy_pages()
1254 mem->pages[i] = NULL; in agp_generic_destroy_pages()
1270 atomic_dec(&agp_bridge->current_memory_agp); in agp_generic_destroy_page()
1279 * agp_enable - initialise the agp point-to-point connection.
1282 * @mode: agp mode register value to configure with.
1288 bridge->driver->agp_enable(bridge, mode); in agp_enable()
1319 if (bridge->driver->masks) in agp_generic_mask_memory()
1320 return addr | bridge->driver->masks[0].mask; in agp_generic_mask_memory()
1347 pci_read_config_word(agp_bridge->dev, agp_bridge->capndx+AGPAPSIZE, &temp_size); in agp3_generic_fetch_size()
1348 values = A_SIZE_16(agp_bridge->driver->aperture_sizes); in agp3_generic_fetch_size()
1350 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) { in agp3_generic_fetch_size()
1352 agp_bridge->previous_size = in agp3_generic_fetch_size()
1353 agp_bridge->current_size = (void *) (values + i); in agp3_generic_fetch_size()
1355 agp_bridge->aperture_size_idx = i; in agp3_generic_fetch_size()
1365 u32 ctrl; in agp3_generic_tlbflush() local
1366 pci_read_config_dword(agp_bridge->dev, agp_bridge->capndx+AGPCTRL, &ctrl); in agp3_generic_tlbflush()
1367 pci_write_config_dword(agp_bridge->dev, agp_bridge->capndx+AGPCTRL, ctrl & ~AGPCTRL_GTLBEN); in agp3_generic_tlbflush()
1368 pci_write_config_dword(agp_bridge->dev, agp_bridge->capndx+AGPCTRL, ctrl); in agp3_generic_tlbflush()
1377 current_size = A_SIZE_16(agp_bridge->current_size); in agp3_generic_configure()
1379 agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev, in agp3_generic_configure()
1383 pci_write_config_word(agp_bridge->dev, agp_bridge->capndx+AGPAPSIZE, current_size->size_value); in agp3_generic_configure()
1385 pci_write_config_dword(agp_bridge->dev, agp_bridge->capndx+AGPGARTLO, agp_bridge->gatt_bus_addr); in agp3_generic_configure()
1387 pci_read_config_dword(agp_bridge->dev, agp_bridge->capndx+AGPCTRL, &temp); in agp3_generic_configure()
1388 …pci_write_config_dword(agp_bridge->dev, agp_bridge->capndx+AGPCTRL, temp | AGPCTRL_APERENB | AGPCT… in agp3_generic_configure()
1395 u32 ctrl; in agp3_generic_cleanup() local
1396 pci_read_config_dword(agp_bridge->dev, agp_bridge->capndx+AGPCTRL, &ctrl); in agp3_generic_cleanup()
1397 pci_write_config_dword(agp_bridge->dev, agp_bridge->capndx+AGPCTRL, ctrl & ~AGPCTRL_APERENB); in agp3_generic_cleanup()