uninorth-agp.c 18 KB

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