uninorth-agp.c 18 KB

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