uninorth-agp.c 17 KB

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