uninorth-agp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * UniNorth AGPGART routines.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/pci.h>
  6. #include <linux/init.h>
  7. #include <linux/pagemap.h>
  8. #include <linux/agp_backend.h>
  9. #include <linux/delay.h>
  10. #include <linux/vmalloc.h>
  11. #include <asm/uninorth.h>
  12. #include <asm/pci-bridge.h>
  13. #include <asm/prom.h>
  14. #include <asm/pmac_feature.h>
  15. #include "agp.h"
  16. /*
  17. * NOTES for uninorth3 (G5 AGP) supports :
  18. *
  19. * There maybe also possibility to have bigger cache line size for
  20. * agp (see pmac_pci.c and look for cache line). Need to be investigated
  21. * by someone.
  22. *
  23. * PAGE size are hardcoded but this may change, see asm/page.h.
  24. *
  25. * Jerome Glisse <j.glisse@gmail.com>
  26. */
  27. static int uninorth_rev;
  28. static int is_u3;
  29. #define DEFAULT_APERTURE_SIZE 256
  30. #define DEFAULT_APERTURE_STRING "256"
  31. static char *aperture = NULL;
  32. static int uninorth_fetch_size(void)
  33. {
  34. int i, size = 0;
  35. struct aper_size_info_32 *values =
  36. A_SIZE_32(agp_bridge->driver->aperture_sizes);
  37. if (aperture) {
  38. char *save = aperture;
  39. size = memparse(aperture, &aperture) >> 20;
  40. aperture = save;
  41. for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++)
  42. if (size == values[i].size)
  43. break;
  44. if (i == agp_bridge->driver->num_aperture_sizes) {
  45. dev_err(&agp_bridge->dev->dev, "invalid aperture size, "
  46. "using default\n");
  47. size = 0;
  48. aperture = NULL;
  49. }
  50. }
  51. if (!size) {
  52. for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++)
  53. if (values[i].size == DEFAULT_APERTURE_SIZE)
  54. break;
  55. }
  56. agp_bridge->previous_size =
  57. agp_bridge->current_size = (void *)(values + i);
  58. agp_bridge->aperture_size_idx = i;
  59. return values[i].size;
  60. }
  61. static void uninorth_tlbflush(struct agp_memory *mem)
  62. {
  63. u32 ctrl = UNI_N_CFG_GART_ENABLE;
  64. if (is_u3)
  65. ctrl |= U3_N_CFG_GART_PERFRD;
  66. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL,
  67. ctrl | UNI_N_CFG_GART_INVAL);
  68. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL, ctrl);
  69. if (uninorth_rev <= 0x30) {
  70. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL,
  71. ctrl | UNI_N_CFG_GART_2xRESET);
  72. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL,
  73. ctrl);
  74. }
  75. }
  76. static void uninorth_cleanup(void)
  77. {
  78. u32 tmp;
  79. pci_read_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL, &tmp);
  80. if (!(tmp & UNI_N_CFG_GART_ENABLE))
  81. return;
  82. tmp |= UNI_N_CFG_GART_INVAL;
  83. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL, tmp);
  84. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL, 0);
  85. if (uninorth_rev <= 0x30) {
  86. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL,
  87. UNI_N_CFG_GART_2xRESET);
  88. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL,
  89. 0);
  90. }
  91. }
  92. static int uninorth_configure(void)
  93. {
  94. struct aper_size_info_32 *current_size;
  95. current_size = A_SIZE_32(agp_bridge->current_size);
  96. dev_info(&agp_bridge->dev->dev, "configuring for size idx: %d\n",
  97. current_size->size_value);
  98. /* aperture size and gatt addr */
  99. pci_write_config_dword(agp_bridge->dev,
  100. UNI_N_CFG_GART_BASE,
  101. (agp_bridge->gatt_bus_addr & 0xfffff000)
  102. | current_size->size_value);
  103. /* HACK ALERT
  104. * UniNorth seem to be buggy enough not to handle properly when
  105. * the AGP aperture isn't mapped at bus physical address 0
  106. */
  107. agp_bridge->gart_bus_addr = 0;
  108. #ifdef CONFIG_PPC64
  109. /* Assume U3 or later on PPC64 systems */
  110. /* high 4 bits of GART physical address go in UNI_N_CFG_AGP_BASE */
  111. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_AGP_BASE,
  112. (agp_bridge->gatt_bus_addr >> 32) & 0xf);
  113. #else
  114. pci_write_config_dword(agp_bridge->dev,
  115. UNI_N_CFG_AGP_BASE, agp_bridge->gart_bus_addr);
  116. #endif
  117. if (is_u3) {
  118. pci_write_config_dword(agp_bridge->dev,
  119. UNI_N_CFG_GART_DUMMY_PAGE,
  120. page_to_phys(agp_bridge->scratch_page_page) >> 12);
  121. }
  122. return 0;
  123. }
  124. static int uninorth_insert_memory(struct agp_memory *mem, off_t pg_start,
  125. int type)
  126. {
  127. int i, j, num_entries;
  128. void *temp;
  129. int mask_type;
  130. temp = agp_bridge->current_size;
  131. num_entries = A_SIZE_32(temp)->num_entries;
  132. if (type != mem->type)
  133. return -EINVAL;
  134. mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
  135. if (mask_type != 0) {
  136. /* We know nothing of memory types */
  137. return -EINVAL;
  138. }
  139. if ((pg_start + mem->page_count) > num_entries)
  140. return -EINVAL;
  141. j = pg_start;
  142. while (j < (pg_start + mem->page_count)) {
  143. if (agp_bridge->gatt_table[j])
  144. return -EBUSY;
  145. j++;
  146. }
  147. for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
  148. agp_bridge->gatt_table[j] =
  149. cpu_to_le32((page_to_phys(mem->pages[i]) & 0xFFFFF000UL) | 0x1UL);
  150. flush_dcache_range((unsigned long)__va(page_to_phys(mem->pages[i])),
  151. (unsigned long)__va(page_to_phys(mem->pages[i]))+0x1000);
  152. }
  153. (void)in_le32((volatile u32*)&agp_bridge->gatt_table[pg_start]);
  154. mb();
  155. uninorth_tlbflush(mem);
  156. return 0;
  157. }
  158. static int u3_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
  159. {
  160. int i, num_entries;
  161. void *temp;
  162. u32 *gp;
  163. int mask_type;
  164. temp = agp_bridge->current_size;
  165. num_entries = A_SIZE_32(temp)->num_entries;
  166. if (type != mem->type)
  167. return -EINVAL;
  168. mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
  169. if (mask_type != 0) {
  170. /* We know nothing of memory types */
  171. return -EINVAL;
  172. }
  173. if ((pg_start + mem->page_count) > num_entries)
  174. return -EINVAL;
  175. gp = (u32 *) &agp_bridge->gatt_table[pg_start];
  176. for (i = 0; i < mem->page_count; ++i) {
  177. if (gp[i]) {
  178. dev_info(&agp_bridge->dev->dev,
  179. "u3_insert_memory: entry 0x%x occupied (%x)\n",
  180. i, gp[i]);
  181. return -EBUSY;
  182. }
  183. }
  184. for (i = 0; i < mem->page_count; i++) {
  185. gp[i] = (page_to_phys(mem->pages[i]) >> PAGE_SHIFT) | 0x80000000UL;
  186. flush_dcache_range((unsigned long)__va(page_to_phys(mem->pages[i])),
  187. (unsigned long)__va(page_to_phys(mem->pages[i]))+0x1000);
  188. }
  189. mb();
  190. uninorth_tlbflush(mem);
  191. return 0;
  192. }
  193. int u3_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
  194. {
  195. size_t i;
  196. u32 *gp;
  197. if (type != 0 || mem->type != 0)
  198. /* We know nothing of memory types */
  199. return -EINVAL;
  200. gp = (u32 *) &agp_bridge->gatt_table[pg_start];
  201. for (i = 0; i < mem->page_count; ++i)
  202. gp[i] = 0;
  203. mb();
  204. uninorth_tlbflush(mem);
  205. return 0;
  206. }
  207. static void uninorth_agp_enable(struct agp_bridge_data *bridge, u32 mode)
  208. {
  209. u32 command, scratch, status;
  210. int timeout;
  211. pci_read_config_dword(bridge->dev,
  212. bridge->capndx + PCI_AGP_STATUS,
  213. &status);
  214. command = agp_collect_device_status(bridge, mode, status);
  215. command |= PCI_AGP_COMMAND_AGP;
  216. if (uninorth_rev == 0x21) {
  217. /*
  218. * Darwin disable AGP 4x on this revision, thus we
  219. * may assume it's broken. This is an AGP2 controller.
  220. */
  221. command &= ~AGPSTAT2_4X;
  222. }
  223. if ((uninorth_rev >= 0x30) && (uninorth_rev <= 0x33)) {
  224. /*
  225. * We need to set REQ_DEPTH to 7 for U3 versions 1.0, 2.1,
  226. * 2.2 and 2.3, Darwin do so.
  227. */
  228. if ((command >> AGPSTAT_RQ_DEPTH_SHIFT) > 7)
  229. command = (command & ~AGPSTAT_RQ_DEPTH)
  230. | (7 << AGPSTAT_RQ_DEPTH_SHIFT);
  231. }
  232. uninorth_tlbflush(NULL);
  233. timeout = 0;
  234. do {
  235. pci_write_config_dword(bridge->dev,
  236. bridge->capndx + PCI_AGP_COMMAND,
  237. command);
  238. pci_read_config_dword(bridge->dev,
  239. bridge->capndx + PCI_AGP_COMMAND,
  240. &scratch);
  241. } while ((scratch & PCI_AGP_COMMAND_AGP) == 0 && ++timeout < 1000);
  242. if ((scratch & PCI_AGP_COMMAND_AGP) == 0)
  243. dev_err(&bridge->dev->dev, "can't write UniNorth AGP "
  244. "command register\n");
  245. if (uninorth_rev >= 0x30) {
  246. /* This is an AGP V3 */
  247. agp_device_command(command, (status & AGPSTAT_MODE_3_0) != 0);
  248. } else {
  249. /* AGP V2 */
  250. agp_device_command(command, false);
  251. }
  252. uninorth_tlbflush(NULL);
  253. }
  254. #ifdef CONFIG_PM
  255. /*
  256. * These Power Management routines are _not_ called by the normal PCI PM layer,
  257. * but directly by the video driver through function pointers in the device
  258. * tree.
  259. */
  260. static int agp_uninorth_suspend(struct pci_dev *pdev)
  261. {
  262. struct agp_bridge_data *bridge;
  263. u32 cmd;
  264. u8 agp;
  265. struct pci_dev *device = NULL;
  266. bridge = agp_find_bridge(pdev);
  267. if (bridge == NULL)
  268. return -ENODEV;
  269. /* Only one suspend supported */
  270. if (bridge->dev_private_data)
  271. return 0;
  272. /* turn off AGP on the video chip, if it was enabled */
  273. for_each_pci_dev(device) {
  274. /* Don't touch the bridge yet, device first */
  275. if (device == pdev)
  276. continue;
  277. /* Only deal with devices on the same bus here, no Mac has a P2P
  278. * bridge on the AGP port, and mucking around the entire PCI
  279. * tree is source of problems on some machines because of a bug
  280. * in some versions of pci_find_capability() when hitting a dead
  281. * device
  282. */
  283. if (device->bus != pdev->bus)
  284. continue;
  285. agp = pci_find_capability(device, PCI_CAP_ID_AGP);
  286. if (!agp)
  287. continue;
  288. pci_read_config_dword(device, agp + PCI_AGP_COMMAND, &cmd);
  289. if (!(cmd & PCI_AGP_COMMAND_AGP))
  290. continue;
  291. dev_info(&pdev->dev, "disabling AGP on device %s\n",
  292. pci_name(device));
  293. cmd &= ~PCI_AGP_COMMAND_AGP;
  294. pci_write_config_dword(device, agp + PCI_AGP_COMMAND, cmd);
  295. }
  296. /* turn off AGP on the bridge */
  297. agp = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  298. pci_read_config_dword(pdev, agp + PCI_AGP_COMMAND, &cmd);
  299. bridge->dev_private_data = (void *)(long)cmd;
  300. if (cmd & PCI_AGP_COMMAND_AGP) {
  301. dev_info(&pdev->dev, "disabling AGP on bridge\n");
  302. cmd &= ~PCI_AGP_COMMAND_AGP;
  303. pci_write_config_dword(pdev, agp + PCI_AGP_COMMAND, cmd);
  304. }
  305. /* turn off the GART */
  306. uninorth_cleanup();
  307. return 0;
  308. }
  309. static int agp_uninorth_resume(struct pci_dev *pdev)
  310. {
  311. struct agp_bridge_data *bridge;
  312. u32 command;
  313. bridge = agp_find_bridge(pdev);
  314. if (bridge == NULL)
  315. return -ENODEV;
  316. command = (long)bridge->dev_private_data;
  317. bridge->dev_private_data = NULL;
  318. if (!(command & PCI_AGP_COMMAND_AGP))
  319. return 0;
  320. uninorth_agp_enable(bridge, command);
  321. return 0;
  322. }
  323. #endif /* CONFIG_PM */
  324. static int uninorth_create_gatt_table(struct agp_bridge_data *bridge)
  325. {
  326. char *table;
  327. char *table_end;
  328. int size;
  329. int page_order;
  330. int num_entries;
  331. int i;
  332. void *temp;
  333. struct page *page;
  334. struct page **pages;
  335. /* We can't handle 2 level gatt's */
  336. if (bridge->driver->size_type == LVL2_APER_SIZE)
  337. return -EINVAL;
  338. table = NULL;
  339. i = bridge->aperture_size_idx;
  340. temp = bridge->current_size;
  341. size = page_order = num_entries = 0;
  342. do {
  343. size = A_SIZE_32(temp)->size;
  344. page_order = A_SIZE_32(temp)->page_order;
  345. num_entries = A_SIZE_32(temp)->num_entries;
  346. table = (char *) __get_free_pages(GFP_KERNEL, page_order);
  347. if (table == NULL) {
  348. i++;
  349. bridge->current_size = A_IDX32(bridge);
  350. } else {
  351. bridge->aperture_size_idx = i;
  352. }
  353. } while (!table && (i < bridge->driver->num_aperture_sizes));
  354. if (table == NULL)
  355. return -ENOMEM;
  356. pages = kmalloc((1 << page_order) * sizeof(struct page*), GFP_KERNEL);
  357. if (pages == NULL)
  358. goto enomem;
  359. table_end = table + ((PAGE_SIZE * (1 << page_order)) - 1);
  360. for (page = virt_to_page(table), i = 0; page <= virt_to_page(table_end);
  361. page++, i++) {
  362. SetPageReserved(page);
  363. pages[i] = page;
  364. }
  365. bridge->gatt_table_real = (u32 *) table;
  366. /* Need to clear out any dirty data still sitting in caches */
  367. flush_dcache_range((unsigned long)table,
  368. (unsigned long)(table_end + PAGE_SIZE));
  369. bridge->gatt_table = vmap(pages, (1 << page_order), 0, PAGE_KERNEL_NCG);
  370. if (bridge->gatt_table == NULL)
  371. goto enomem;
  372. bridge->gatt_bus_addr = virt_to_phys(table);
  373. for (i = 0; i < num_entries; i++)
  374. bridge->gatt_table[i] = 0;
  375. return 0;
  376. enomem:
  377. kfree(pages);
  378. if (table)
  379. free_pages((unsigned long)table, page_order);
  380. return -ENOMEM;
  381. }
  382. static int uninorth_free_gatt_table(struct agp_bridge_data *bridge)
  383. {
  384. int page_order;
  385. char *table, *table_end;
  386. void *temp;
  387. struct page *page;
  388. temp = bridge->current_size;
  389. page_order = A_SIZE_32(temp)->page_order;
  390. /* Do not worry about freeing memory, because if this is
  391. * called, then all agp memory is deallocated and removed
  392. * from the table.
  393. */
  394. vunmap(bridge->gatt_table);
  395. table = (char *) bridge->gatt_table_real;
  396. table_end = table + ((PAGE_SIZE * (1 << page_order)) - 1);
  397. for (page = virt_to_page(table); page <= virt_to_page(table_end); page++)
  398. ClearPageReserved(page);
  399. free_pages((unsigned long) bridge->gatt_table_real, page_order);
  400. return 0;
  401. }
  402. void null_cache_flush(void)
  403. {
  404. mb();
  405. }
  406. /* Setup function */
  407. static const struct aper_size_info_32 uninorth_sizes[] =
  408. {
  409. {256, 65536, 6, 64},
  410. {128, 32768, 5, 32},
  411. {64, 16384, 4, 16},
  412. {32, 8192, 3, 8},
  413. {16, 4096, 2, 4},
  414. {8, 2048, 1, 2},
  415. {4, 1024, 0, 1}
  416. };
  417. /*
  418. * Not sure that u3 supports that high aperture sizes but it
  419. * would strange if it did not :)
  420. */
  421. static const struct aper_size_info_32 u3_sizes[] =
  422. {
  423. {512, 131072, 7, 128},
  424. {256, 65536, 6, 64},
  425. {128, 32768, 5, 32},
  426. {64, 16384, 4, 16},
  427. {32, 8192, 3, 8},
  428. {16, 4096, 2, 4},
  429. {8, 2048, 1, 2},
  430. {4, 1024, 0, 1}
  431. };
  432. const struct agp_bridge_driver uninorth_agp_driver = {
  433. .owner = THIS_MODULE,
  434. .aperture_sizes = (void *)uninorth_sizes,
  435. .size_type = U32_APER_SIZE,
  436. .num_aperture_sizes = ARRAY_SIZE(uninorth_sizes),
  437. .configure = uninorth_configure,
  438. .fetch_size = uninorth_fetch_size,
  439. .cleanup = uninorth_cleanup,
  440. .tlb_flush = uninorth_tlbflush,
  441. .mask_memory = agp_generic_mask_memory,
  442. .masks = NULL,
  443. .cache_flush = null_cache_flush,
  444. .agp_enable = uninorth_agp_enable,
  445. .create_gatt_table = uninorth_create_gatt_table,
  446. .free_gatt_table = uninorth_free_gatt_table,
  447. .insert_memory = uninorth_insert_memory,
  448. .remove_memory = agp_generic_remove_memory,
  449. .alloc_by_type = agp_generic_alloc_by_type,
  450. .free_by_type = agp_generic_free_by_type,
  451. .agp_alloc_page = agp_generic_alloc_page,
  452. .agp_alloc_pages = agp_generic_alloc_pages,
  453. .agp_destroy_page = agp_generic_destroy_page,
  454. .agp_destroy_pages = agp_generic_destroy_pages,
  455. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  456. .cant_use_aperture = true,
  457. };
  458. const struct agp_bridge_driver u3_agp_driver = {
  459. .owner = THIS_MODULE,
  460. .aperture_sizes = (void *)u3_sizes,
  461. .size_type = U32_APER_SIZE,
  462. .num_aperture_sizes = ARRAY_SIZE(u3_sizes),
  463. .configure = uninorth_configure,
  464. .fetch_size = uninorth_fetch_size,
  465. .cleanup = uninorth_cleanup,
  466. .tlb_flush = uninorth_tlbflush,
  467. .mask_memory = agp_generic_mask_memory,
  468. .masks = NULL,
  469. .cache_flush = null_cache_flush,
  470. .agp_enable = uninorth_agp_enable,
  471. .create_gatt_table = uninorth_create_gatt_table,
  472. .free_gatt_table = uninorth_free_gatt_table,
  473. .insert_memory = u3_insert_memory,
  474. .remove_memory = u3_remove_memory,
  475. .alloc_by_type = agp_generic_alloc_by_type,
  476. .free_by_type = agp_generic_free_by_type,
  477. .agp_alloc_page = agp_generic_alloc_page,
  478. .agp_alloc_pages = agp_generic_alloc_pages,
  479. .agp_destroy_page = agp_generic_destroy_page,
  480. .agp_destroy_pages = agp_generic_destroy_pages,
  481. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  482. .cant_use_aperture = true,
  483. .needs_scratch_page = true,
  484. };
  485. static struct agp_device_ids uninorth_agp_device_ids[] __devinitdata = {
  486. {
  487. .device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP,
  488. .chipset_name = "UniNorth",
  489. },
  490. {
  491. .device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP_P,
  492. .chipset_name = "UniNorth/Pangea",
  493. },
  494. {
  495. .device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP15,
  496. .chipset_name = "UniNorth 1.5",
  497. },
  498. {
  499. .device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP2,
  500. .chipset_name = "UniNorth 2",
  501. },
  502. {
  503. .device_id = PCI_DEVICE_ID_APPLE_U3_AGP,
  504. .chipset_name = "U3",
  505. },
  506. {
  507. .device_id = PCI_DEVICE_ID_APPLE_U3L_AGP,
  508. .chipset_name = "U3L",
  509. },
  510. {
  511. .device_id = PCI_DEVICE_ID_APPLE_U3H_AGP,
  512. .chipset_name = "U3H",
  513. },
  514. {
  515. .device_id = PCI_DEVICE_ID_APPLE_IPID2_AGP,
  516. .chipset_name = "UniNorth/Intrepid2",
  517. },
  518. };
  519. static int __devinit agp_uninorth_probe(struct pci_dev *pdev,
  520. const struct pci_device_id *ent)
  521. {
  522. struct agp_device_ids *devs = uninorth_agp_device_ids;
  523. struct agp_bridge_data *bridge;
  524. struct device_node *uninorth_node;
  525. u8 cap_ptr;
  526. int j;
  527. cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  528. if (cap_ptr == 0)
  529. return -ENODEV;
  530. /* probe for known chipsets */
  531. for (j = 0; devs[j].chipset_name != NULL; ++j) {
  532. if (pdev->device == devs[j].device_id) {
  533. dev_info(&pdev->dev, "Apple %s chipset\n",
  534. devs[j].chipset_name);
  535. goto found;
  536. }
  537. }
  538. dev_err(&pdev->dev, "unsupported Apple chipset [%04x/%04x]\n",
  539. pdev->vendor, pdev->device);
  540. return -ENODEV;
  541. found:
  542. /* Set revision to 0 if we could not read it. */
  543. uninorth_rev = 0;
  544. is_u3 = 0;
  545. /* Locate core99 Uni-N */
  546. uninorth_node = of_find_node_by_name(NULL, "uni-n");
  547. /* Locate G5 u3 */
  548. if (uninorth_node == NULL) {
  549. is_u3 = 1;
  550. uninorth_node = of_find_node_by_name(NULL, "u3");
  551. }
  552. if (uninorth_node) {
  553. const int *revprop = of_get_property(uninorth_node,
  554. "device-rev", NULL);
  555. if (revprop != NULL)
  556. uninorth_rev = *revprop & 0x3f;
  557. of_node_put(uninorth_node);
  558. }
  559. #ifdef CONFIG_PM
  560. /* Inform platform of our suspend/resume caps */
  561. pmac_register_agp_pm(pdev, agp_uninorth_suspend, agp_uninorth_resume);
  562. #endif
  563. /* Allocate & setup our driver */
  564. bridge = agp_alloc_bridge();
  565. if (!bridge)
  566. return -ENOMEM;
  567. if (is_u3)
  568. bridge->driver = &u3_agp_driver;
  569. else
  570. bridge->driver = &uninorth_agp_driver;
  571. bridge->dev = pdev;
  572. bridge->capndx = cap_ptr;
  573. bridge->flags = AGP_ERRATA_FASTWRITES;
  574. /* Fill in the mode register */
  575. pci_read_config_dword(pdev, cap_ptr+PCI_AGP_STATUS, &bridge->mode);
  576. pci_set_drvdata(pdev, bridge);
  577. return agp_add_bridge(bridge);
  578. }
  579. static void __devexit agp_uninorth_remove(struct pci_dev *pdev)
  580. {
  581. struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
  582. #ifdef CONFIG_PM
  583. /* Inform platform of our suspend/resume caps */
  584. pmac_register_agp_pm(pdev, NULL, NULL);
  585. #endif
  586. agp_remove_bridge(bridge);
  587. agp_put_bridge(bridge);
  588. }
  589. static struct pci_device_id agp_uninorth_pci_table[] = {
  590. {
  591. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  592. .class_mask = ~0,
  593. .vendor = PCI_VENDOR_ID_APPLE,
  594. .device = PCI_ANY_ID,
  595. .subvendor = PCI_ANY_ID,
  596. .subdevice = PCI_ANY_ID,
  597. },
  598. { }
  599. };
  600. MODULE_DEVICE_TABLE(pci, agp_uninorth_pci_table);
  601. static struct pci_driver agp_uninorth_pci_driver = {
  602. .name = "agpgart-uninorth",
  603. .id_table = agp_uninorth_pci_table,
  604. .probe = agp_uninorth_probe,
  605. .remove = agp_uninorth_remove,
  606. };
  607. static int __init agp_uninorth_init(void)
  608. {
  609. if (agp_off)
  610. return -EINVAL;
  611. return pci_register_driver(&agp_uninorth_pci_driver);
  612. }
  613. static void __exit agp_uninorth_cleanup(void)
  614. {
  615. pci_unregister_driver(&agp_uninorth_pci_driver);
  616. }
  617. module_init(agp_uninorth_init);
  618. module_exit(agp_uninorth_cleanup);
  619. module_param(aperture, charp, 0);
  620. MODULE_PARM_DESC(aperture,
  621. "Aperture size, must be power of two between 4MB and an\n"
  622. "\t\tupper limit specific to the UniNorth revision.\n"
  623. "\t\tDefault: " DEFAULT_APERTURE_STRING "M");
  624. MODULE_AUTHOR("Ben Herrenschmidt & Paul Mackerras");
  625. MODULE_LICENSE("GPL");