uninorth-agp.c 18 KB

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