uninorth-agp.c 18 KB

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