Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #include "types.h"
  3.  
  4. #include <stdio.h>
  5. #include <malloc.h>
  6. #include <memory.h>
  7.  
  8. #include "pci.h"
  9. #include "agp.h"
  10.  
  11. #include "syscall.h"
  12.  
  13.  
  14. agp_t agp_dev;
  15.  
  16.  
  17. int __stdcall srv_agp(ioctl_t *io);
  18.  
  19.  
  20. u32_t __stdcall drvEntry(int action)
  21. {
  22.     u32_t retval;
  23.  
  24.     int i;
  25.  
  26.     if(action != 1)
  27.         return 0;
  28.  
  29.     if(!dbg_open("/rd/1/drivers/agp.log"))
  30.     {
  31.         printf("Can't open /rd/1/drivers/agp.log\nExit\n");
  32.         return 0;
  33.     }
  34.  
  35.     if( FindPciDevice() == 0)
  36.     {
  37.         dbgprintf("Device not found\n");
  38.         return 0;
  39.     };
  40.  
  41.     return 0;
  42.  
  43. //    retval = RegService("AGP", srv_2d);
  44. //    dbgprintf("reg service %s as: %x\n", "HDRAW", retval);
  45.  
  46. //    return retval;
  47. };
  48.  
  49.  
  50. static void intel_8xx_tlbflush(void *mem)
  51. {
  52.     u32_t temp;
  53.  
  54.     temp = pciReadLong(agp_dev.PciTag, INTEL_AGPCTRL);
  55.     pciWriteLong(agp_dev.PciTag, INTEL_AGPCTRL, temp & ~(1 << 7));
  56.     temp = pciReadLong(agp_dev.PciTag, INTEL_AGPCTRL);
  57.     pciWriteLong(agp_dev.PciTag, INTEL_AGPCTRL, temp | (1 << 7));
  58. }
  59.  
  60.  
  61. static aper_size_t intel_8xx_sizes[7] =
  62. {
  63.     { 256, 65536, 64,  0 },
  64.     { 128, 32768, 32, 32 },
  65.     {  64, 16384, 16, 48 },
  66.     {  32,  8192,  8, 56 },
  67.     {  16,  4096,  4, 60 },
  68.     {   8,  2048,  2, 62 },
  69.     {   4,  1024,  1, 63 }
  70. };
  71.  
  72. #if 0
  73. static int agp_backend_initialize(struct agp_bridge_data *bridge)
  74. {
  75.         int size_value, rc, got_gatt=0, got_keylist=0;
  76.  
  77.         bridge->max_memory_agp = agp_find_max();
  78.         bridge->version = &agp_current_version;
  79.  
  80.         if (bridge->driver->needs_scratch_page) {
  81.                 void *addr = bridge->driver->agp_alloc_page(bridge);
  82.  
  83.                 if (!addr) {
  84.                         printk(KERN_ERR PFX "unable to get memory for scratch page.\n");
  85.                         return -ENOMEM;
  86.                 }
  87.                 flush_agp_mappings();
  88.  
  89.                 bridge->scratch_page_real = virt_to_gart(addr);
  90.                 bridge->scratch_page =
  91.                     bridge->driver->mask_memory(bridge, bridge->scratch_page_real, 0);
  92.         }
  93.  
  94.         size_value = bridge->driver->fetch_size();
  95.         if (size_value == 0) {
  96.                 printk(KERN_ERR PFX "unable to determine aperture size.\n");
  97.                 rc = -EINVAL;
  98.                 goto err_out;
  99.         }
  100.         if (bridge->driver->create_gatt_table(bridge)) {
  101.                 printk(KERN_ERR PFX
  102.                     "unable to get memory for graphics translation table.\n");
  103.                 rc = -ENOMEM;
  104.                 goto err_out;
  105.         }
  106.         got_gatt = 1;
  107.  
  108.         bridge->key_list = vmalloc(PAGE_SIZE * 4);
  109.         if (bridge->key_list == NULL) {
  110.                 printk(KERN_ERR PFX "error allocating memory for key lists.\n");
  111.                 rc = -ENOMEM;
  112.                 goto err_out;
  113.         }
  114.         got_keylist = 1;
  115.  
  116.         /* FIXME vmalloc'd memory not guaranteed contiguous */
  117.         memset(bridge->key_list, 0, PAGE_SIZE * 4);
  118.  
  119.         if (bridge->driver->configure()) {
  120.                 printk(KERN_ERR PFX "error configuring host chipset.\n");
  121.                 rc = -EINVAL;
  122.                 goto err_out;
  123.         }
  124.  
  125.         return 0;
  126.  
  127. err_out:
  128.         if (bridge->driver->needs_scratch_page) {
  129.                 bridge->driver->agp_destroy_page(
  130.                                 gart_to_virt(bridge->scratch_page_real));
  131.                 flush_agp_mappings();
  132.         }
  133.         if (got_gatt)
  134.                 bridge->driver->free_gatt_table(bridge);
  135.         if (got_keylist) {
  136.                 vfree(bridge->key_list);
  137.                 bridge->key_list = NULL;
  138.         }
  139.         return rc;
  140. }
  141.  
  142.  
  143. #endif
  144.  
  145.  
  146. static int intel_845_configure(void *bridge)
  147. {
  148.     u32_t temp;
  149.     u8_t  temp2;
  150.     aper_size_t *current_size;
  151.  
  152.     agp_t *agp = (agp_t*)bridge;
  153.  
  154.     current_size = agp->current_size;
  155.  
  156.         /* aperture size */
  157.     pciWriteByte(agp->PciTag, INTEL_APSIZE, current_size->size_value);
  158.  
  159.     dbgprintf("INTEL_APSIZE %d\n", current_size->size_value );
  160.  
  161.     if (agp->apbase_config != 0)
  162.     {
  163.         pciWriteLong(agp->PciTag, AGP_APBASE, agp->apbase_config);
  164.     }
  165.     else
  166.     {
  167.                 /* address to map to */
  168.         temp = pciReadLong(agp->PciTag, AGP_APBASE);
  169.         agp->gart_addr = (temp & PCI_MAP_MEMORY_ADDRESS_MASK);
  170.         agp->apbase_config = temp;
  171.         }
  172.  
  173.     dbgprintf("AGP_APBASE %x\n", temp );
  174.  
  175.         /* attbase - aperture base */
  176.     pciWriteLong(agp->PciTag, INTEL_ATTBASE, agp->gatt_dma);
  177.  
  178.         /* agpctrl */
  179.     pciWriteLong(agp->PciTag, INTEL_AGPCTRL, 0x0000);
  180.  
  181.         /* agpm */
  182.     temp2 = pciReadByte(agp->PciTag, INTEL_I845_AGPM);
  183.     pciWriteByte(agp->PciTag, INTEL_I845_AGPM, temp2 | (1 << 1));
  184.         /* clear any possible error conditions */
  185.     pciWriteWord(agp->PciTag, INTEL_I845_ERRSTS, 0x001c);
  186.         return 0;
  187. }
  188.  
  189.  
  190. int agp_generic_create_gatt_table(agp_t *bridge)
  191. {
  192.     count_t pages;
  193.  
  194.     pages = bridge->current_size->pages_count;
  195.  
  196.     bridge->gatt_dma = AllocPages(pages);
  197.  
  198.     bridge->gatt_table = (u32_t*)MapIoMem((void*)bridge->gatt_dma,
  199.                                      pages<<12, PG_SW+PG_NOCACHE);
  200.  
  201.     dbgprintf("gatt map %x at %x %d pages\n",bridge->gatt_dma ,
  202.                bridge->gatt_table, pages);
  203.  
  204.     if (bridge->gatt_table == NULL)
  205.         return -30;//ENOMEM;
  206.  
  207.         /* AK: bogus, should encode addresses > 4GB */
  208. //    for (i = 0; i < num_entries; i++) {
  209. //        writel(bridge->scratch_page, bridge->gatt_table+i);
  210. //        readl(bridge->gatt_table+i);    /* PCI Posting. */
  211. //    }
  212.  
  213.         return 0;
  214. }
  215.  
  216.  
  217.  
  218. static int __intel_8xx_fetch_size(u8_t temp)
  219. {
  220.         int i;
  221.     aper_size_t *values;
  222.  
  223.    // values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
  224.  
  225.     values = intel_8xx_sizes;
  226.  
  227.     for (i = 0; i < 7; i++)
  228.     {
  229.         if (temp == values[i].size_value)
  230.         {
  231.             agp_dev.previous_size =
  232.                 agp_dev.current_size = (void *) (values + i);
  233.             agp_dev.aperture_size_idx = i;
  234.                         return values[i].size;
  235.                 }
  236.         }
  237.         return 0;
  238. }
  239.  
  240. static int intel_8xx_fetch_size(void)
  241. {
  242.     u8_t temp;
  243.  
  244.     temp = pciReadByte(agp_dev.PciTag, INTEL_APSIZE);
  245.         return __intel_8xx_fetch_size(temp);
  246. }
  247.  
  248.  
  249. int agp_bind_memory(addr_t agp_addr, addr_t dma_addr, size_t size)
  250. {
  251.         int ret_val;
  252.     count_t count;
  253.  
  254. //    if (curr == NULL)
  255. //        return -EINVAL;
  256.  
  257. //    if (curr->is_bound == TRUE) {
  258. //        printk(KERN_INFO PFX "memory %p is already bound!\n", curr);
  259. //        return -EINVAL;
  260. //    }
  261. //    if (curr->is_flushed == FALSE) {
  262. //        curr->bridge->driver->cache_flush();
  263. //        curr->is_flushed = TRUE;
  264. //    }
  265. //    ret_val = curr->bridge->driver->insert_memory(curr, pg_start, curr->type);
  266.  
  267.     u32_t volatile *table = &agp_dev.gatt_table[agp_addr>>12];
  268.  
  269.     count = size >> 12;
  270.  
  271.     dma_addr |= 0x00000017;
  272.  
  273.     while(count--)
  274.     {
  275.         addr_t tmp;
  276.  
  277.         *table = dma_addr;
  278.         tmp = *table;                    /* PCI Posting. */
  279.         table++;
  280.         dma_addr+=4096;
  281.     }
  282.  
  283.     agp_dev.tlb_flush(NULL);
  284.  
  285. //    if (ret_val != 0)
  286. //        return ret_val;
  287.  
  288. //    curr->is_bound = TRUE;
  289. //    curr->pg_start = pg_start;
  290.         return 0;
  291. }
  292.  
  293.  
  294. static agp_t intel_845_driver =
  295. {
  296. //    .aperture_sizes     = intel_8xx_sizes,
  297. //    .size_type          = U8_APER_SIZE,
  298. //    .num_aperture_sizes = 7,
  299.     .configure          = intel_845_configure,
  300.     .fetch_size         = intel_8xx_fetch_size,
  301. //    .cleanup            = intel_8xx_cleanup,
  302.     .tlb_flush          = intel_8xx_tlbflush,
  303. //    .mask_memory        = agp_generic_mask_memory,
  304. //    .masks              = intel_generic_masks,
  305. //    .agp_enable         = agp_generic_enable,
  306. //    .cache_flush        = global_cache_flush,
  307. //    .create_gatt_table  = agp_generic_create_gatt_table,
  308. //    .free_gatt_table    = agp_generic_free_gatt_table,
  309. //    .insert_memory      = agp_generic_insert_memory,
  310. //    .remove_memory      = agp_generic_remove_memory,
  311. //    .alloc_by_type      = agp_generic_alloc_by_type,
  312. //    .free_by_type       = agp_generic_free_by_type,
  313. //    .agp_alloc_page     = agp_generic_alloc_page,
  314. //    .agp_destroy_page   = agp_generic_destroy_page,
  315. };
  316.  
  317.  
  318. #include "detect.inc"
  319.