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. #define DEFAULT_APERTURE_SIZE 256
  29. #define DEFAULT_APERTURE_STRING "256"
  30. static char *aperture = NULL;
  31. static int uninorth_fetch_size(void)
  32. {
  33. int i, size = 0;
  34. struct aper_size_info_32 *values =
  35. A_SIZE_32(agp_bridge->driver->aperture_sizes);
  36. if (aperture) {
  37. char *save = aperture;
  38. size = memparse(aperture, &aperture) >> 20;
  39. aperture = save;
  40. for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++)
  41. if (size == values[i].size)
  42. break;
  43. if (i == agp_bridge->driver->num_aperture_sizes) {
  44. dev_err(&agp_bridge->dev->dev, "invalid aperture size, "
  45. "using default\n");
  46. size = 0;
  47. aperture = NULL;
  48. }
  49. }
  50. if (!size) {
  51. for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++)
  52. if (values[i].size == DEFAULT_APERTURE_SIZE)
  53. break;
  54. }
  55. agp_bridge->previous_size =
  56. agp_bridge->current_size = (void *)(values + i);
  57. agp_bridge->aperture_size_idx = i;
  58. return values[i].size;
  59. }
  60. static void uninorth_tlbflush(struct agp_memory *mem)
  61. {
  62. u32 ctrl = UNI_N_CFG_GART_ENABLE;
  63. if (is_u3)
  64. ctrl |= U3_N_CFG_GART_PERFRD;
  65. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL,
  66. ctrl | UNI_N_CFG_GART_INVAL);
  67. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL, ctrl);
  68. if (uninorth_rev <= 0x30) {
  69. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL,
  70. ctrl | UNI_N_CFG_GART_2xRESET);
  71. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL,
  72. ctrl);
  73. }
  74. }
  75. static void uninorth_cleanup(void)
  76. {
  77. u32 tmp;
  78. pci_read_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL, &tmp);
  79. if (!(tmp & UNI_N_CFG_GART_ENABLE))
  80. return;
  81. tmp |= UNI_N_CFG_GART_INVAL;
  82. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL, tmp);
  83. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL, 0);
  84. if (uninorth_rev <= 0x30) {
  85. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL,
  86. UNI_N_CFG_GART_2xRESET);
  87. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_GART_CTRL,
  88. 0);
  89. }
  90. }
  91. static int uninorth_configure(void)
  92. {
  93. struct aper_size_info_32 *current_size;
  94. current_size = A_SIZE_32(agp_bridge->current_size);
  95. dev_info(&agp_bridge->dev->dev, "configuring for size idx: %d\n",
  96. current_size->size_value);
  97. /* aperture size and gatt addr */
  98. pci_write_config_dword(agp_bridge->dev,
  99. UNI_N_CFG_GART_BASE,
  100. (agp_bridge->gatt_bus_addr & 0xfffff000)
  101. | current_size->size_value);
  102. /* HACK ALERT
  103. * UniNorth seem to be buggy enough not to handle properly when
  104. * the AGP aperture isn't mapped at bus physical address 0
  105. */
  106. agp_bridge->gart_bus_addr = 0;
  107. #ifdef CONFIG_PPC64
  108. /* Assume U3 or later on PPC64 systems */
  109. /* high 4 bits of GART physical address go in UNI_N_CFG_AGP_BASE */
  110. pci_write_config_dword(agp_bridge->dev, UNI_N_CFG_AGP_BASE,
  111. (agp_bridge->gatt_bus_addr >> 32) & 0xf);
  112. #else
  113. pci_write_config_dword(agp_bridge->dev,
  114. UNI_N_CFG_AGP_BASE, agp_bridge->gart_bus_addr);
  115. #endif
  116. if (is_u3) {
  117. pci_write_config_dword(agp_bridge->dev,
  118. UNI_N_CFG_GART_DUMMY_PAGE,
  119. agp_bridge->scratch_page_real >> 12);
  120. }
  121. return 0;
  122. }
  123. static int uninorth_insert_memory(struct agp_memory *mem, off_t pg_start,
  124. int type)
  125. {
  126. int i, j, num_entries;
  127. void *temp;
  128. int mask_type;
  129. temp = agp_bridge->current_size;
  130. num_entries = A_SIZE_32(temp)->num_entries;
  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 ((pg_start + mem->page_count) > num_entries)
  139. return -EINVAL;
  140. j = pg_start;
  141. while (j < (pg_start + mem->page_count)) {
  142. if (agp_bridge->gatt_table[j])
  143. return -EBUSY;
  144. j++;
  145. }
  146. for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
  147. agp_bridge->gatt_table[j] =
  148. cpu_to_le32((page_to_phys(mem->pages[i]) & 0xFFFFF000UL) | 0x1UL);
  149. flush_dcache_range((unsigned long)__va(page_to_phys(mem->pages[i])),
  150. (unsigned long)__va(page_to_phys(mem->pages[i]))+0x1000);
  151. }
  152. (void)in_le32((volatile u32*)&agp_bridge->gatt_table[pg_start]);
  153. mb();
  154. flush_dcache_range((unsigned long)&agp_bridge->gatt_table[pg_start],
  155. (unsigned long)&agp_bridge->gatt_table[pg_start + mem->page_count]);
  156. uninorth_tlbflush(mem);
  157. return 0;
  158. }
  159. static int u3_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
  160. {
  161. int i, num_entries;
  162. void *temp;
  163. u32 *gp;
  164. int mask_type;
  165. temp = agp_bridge->current_size;
  166. num_entries = A_SIZE_32(temp)->num_entries;
  167. if (type != mem->type)
  168. return -EINVAL;
  169. mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
  170. if (mask_type != 0) {
  171. /* We know nothing of memory types */
  172. return -EINVAL;
  173. }
  174. if ((pg_start + mem->page_count) > num_entries)
  175. return -EINVAL;
  176. gp = (u32 *) &agp_bridge->gatt_table[pg_start];
  177. for (i = 0; i < mem->page_count; ++i) {
  178. if (gp[i]) {
  179. dev_info(&agp_bridge->dev->dev,
  180. "u3_insert_memory: entry 0x%x occupied (%x)\n",
  181. i, gp[i]);
  182. return -EBUSY;
  183. }
  184. }
  185. for (i = 0; i < mem->page_count; i++) {
  186. gp[i] = (page_to_phys(mem->pages[i]) >> PAGE_SHIFT) | 0x80000000UL;
  187. flush_dcache_range((unsigned long)__va(page_to_phys(mem->pages[i])),
  188. (unsigned long)__va(page_to_phys(mem->pages[i]))+0x1000);
  189. }
  190. mb();
  191. flush_dcache_range((unsigned long)gp, (unsigned long) &gp[i]);
  192. uninorth_tlbflush(mem);
  193. return 0;
  194. }
  195. int u3_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
  196. {
  197. size_t i;
  198. u32 *gp;
  199. if (type != 0 || mem->type != 0)
  200. /* We know nothing of memory types */
  201. return -EINVAL;
  202. gp = (u32 *) &agp_bridge->gatt_table[pg_start];
  203. for (i = 0; i < mem->page_count; ++i)
  204. gp[i] = 0;
  205. mb();
  206. flush_dcache_range((unsigned long)gp, (unsigned long) &gp[i]);
  207. uninorth_tlbflush(mem);
  208. return 0;
  209. }
  210. static void uninorth_agp_enable(struct agp_bridge_data *bridge, u32 mode)
  211. {
  212. u32 command, scratch, status;
  213. int timeout;
  214. pci_read_config_dword(bridge->dev,
  215. bridge->capndx + PCI_AGP_STATUS,
  216. &status);
  217. command = agp_collect_device_status(bridge, mode, status);
  218. command |= PCI_AGP_COMMAND_AGP;
  219. if (uninorth_rev == 0x21) {
  220. /*
  221. * Darwin disable AGP 4x on this revision, thus we
  222. * may assume it's broken. This is an AGP2 controller.
  223. */
  224. command &= ~AGPSTAT2_4X;
  225. }
  226. if ((uninorth_rev >= 0x30) && (uninorth_rev <= 0x33)) {
  227. /*
  228. * We need to to set REQ_DEPTH to 7 for U3 versions 1.0, 2.1,
  229. * 2.2 and 2.3, Darwin do so.
  230. */
  231. if ((command >> AGPSTAT_RQ_DEPTH_SHIFT) > 7)
  232. command = (command & ~AGPSTAT_RQ_DEPTH)
  233. | (7 << AGPSTAT_RQ_DEPTH_SHIFT);
  234. }
  235. uninorth_tlbflush(NULL);
  236. timeout = 0;
  237. do {
  238. pci_write_config_dword(bridge->dev,
  239. bridge->capndx + PCI_AGP_COMMAND,
  240. command);
  241. pci_read_config_dword(bridge->dev,
  242. bridge->capndx + PCI_AGP_COMMAND,
  243. &scratch);
  244. } while ((scratch & PCI_AGP_COMMAND_AGP) == 0 && ++timeout < 1000);
  245. if ((scratch & PCI_AGP_COMMAND_AGP) == 0)
  246. dev_err(&bridge->dev->dev, "can't write UniNorth AGP "
  247. "command register\n");
  248. if (uninorth_rev >= 0x30) {
  249. /* This is an AGP V3 */
  250. agp_device_command(command, (status & AGPSTAT_MODE_3_0) != 0);
  251. } else {
  252. /* AGP V2 */
  253. agp_device_command(command, false);
  254. }
  255. uninorth_tlbflush(NULL);
  256. }
  257. #ifdef CONFIG_PM
  258. /*
  259. * These Power Management routines are _not_ called by the normal PCI PM layer,
  260. * but directly by the video driver through function pointers in the device
  261. * tree.
  262. */
  263. static int agp_uninorth_suspend(struct pci_dev *pdev)
  264. {
  265. struct agp_bridge_data *bridge;
  266. u32 cmd;
  267. u8 agp;
  268. struct pci_dev *device = NULL;
  269. bridge = agp_find_bridge(pdev);
  270. if (bridge == NULL)
  271. return -ENODEV;
  272. /* Only one suspend supported */
  273. if (bridge->dev_private_data)
  274. return 0;
  275. /* turn off AGP on the video chip, if it was enabled */
  276. for_each_pci_dev(device) {
  277. /* Don't touch the bridge yet, device first */
  278. if (device == pdev)
  279. continue;
  280. /* Only deal with devices on the same bus here, no Mac has a P2P
  281. * bridge on the AGP port, and mucking around the entire PCI
  282. * tree is source of problems on some machines because of a bug
  283. * in some versions of pci_find_capability() when hitting a dead
  284. * device
  285. */
  286. if (device->bus != pdev->bus)
  287. continue;
  288. agp = pci_find_capability(device, PCI_CAP_ID_AGP);
  289. if (!agp)
  290. continue;
  291. pci_read_config_dword(device, agp + PCI_AGP_COMMAND, &cmd);
  292. if (!(cmd & PCI_AGP_COMMAND_AGP))
  293. continue;
  294. dev_info(&pdev->dev, "disabling AGP on device %s\n",
  295. pci_name(device));
  296. cmd &= ~PCI_AGP_COMMAND_AGP;
  297. pci_write_config_dword(device, agp + PCI_AGP_COMMAND, cmd);
  298. }
  299. /* turn off AGP on the bridge */
  300. agp = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  301. pci_read_config_dword(pdev, agp + PCI_AGP_COMMAND, &cmd);
  302. bridge->dev_private_data = (void *)(long)cmd;
  303. if (cmd & PCI_AGP_COMMAND_AGP) {
  304. dev_info(&pdev->dev, "disabling AGP on bridge\n");
  305. cmd &= ~PCI_AGP_COMMAND_AGP;
  306. pci_write_config_dword(pdev, agp + PCI_AGP_COMMAND, cmd);
  307. }
  308. /* turn off the GART */
  309. uninorth_cleanup();
  310. return 0;
  311. }
  312. static int agp_uninorth_resume(struct pci_dev *pdev)
  313. {
  314. struct agp_bridge_data *bridge;
  315. u32 command;
  316. bridge = agp_find_bridge(pdev);
  317. if (bridge == NULL)
  318. return -ENODEV;
  319. command = (long)bridge->dev_private_data;
  320. bridge->dev_private_data = NULL;
  321. if (!(command & PCI_AGP_COMMAND_AGP))
  322. return 0;
  323. uninorth_agp_enable(bridge, command);
  324. return 0;
  325. }
  326. #endif /* CONFIG_PM */
  327. static int uninorth_create_gatt_table(struct agp_bridge_data *bridge)
  328. {
  329. char *table;
  330. char *table_end;
  331. int size;
  332. int page_order;
  333. int num_entries;
  334. int i;
  335. void *temp;
  336. struct page *page;
  337. /* We can't handle 2 level gatt's */
  338. if (bridge->driver->size_type == LVL2_APER_SIZE)
  339. return -EINVAL;
  340. table = NULL;
  341. i = bridge->aperture_size_idx;
  342. temp = bridge->current_size;
  343. size = page_order = num_entries = 0;
  344. do {
  345. size = A_SIZE_32(temp)->size;
  346. page_order = A_SIZE_32(temp)->page_order;
  347. num_entries = A_SIZE_32(temp)->num_entries;
  348. table = (char *) __get_free_pages(GFP_KERNEL, page_order);
  349. if (table == NULL) {
  350. i++;
  351. bridge->current_size = A_IDX32(bridge);
  352. } else {
  353. bridge->aperture_size_idx = i;
  354. }
  355. } while (!table && (i < bridge->driver->num_aperture_sizes));
  356. if (table == NULL)
  357. return -ENOMEM;
  358. table_end = table + ((PAGE_SIZE * (1 << page_order)) - 1);
  359. for (page = virt_to_page(table); page <= virt_to_page(table_end); page++)
  360. SetPageReserved(page);
  361. bridge->gatt_table_real = (u32 *) table;
  362. bridge->gatt_table = (u32 *)table;
  363. bridge->gatt_bus_addr = virt_to_gart(table);
  364. for (i = 0; i < num_entries; i++)
  365. bridge->gatt_table[i] = 0;
  366. flush_dcache_range((unsigned long)table, (unsigned long)table_end);
  367. return 0;
  368. }
  369. static int uninorth_free_gatt_table(struct agp_bridge_data *bridge)
  370. {
  371. int page_order;
  372. char *table, *table_end;
  373. void *temp;
  374. struct page *page;
  375. temp = bridge->current_size;
  376. page_order = A_SIZE_32(temp)->page_order;
  377. /* Do not worry about freeing memory, because if this is
  378. * called, then all agp memory is deallocated and removed
  379. * from the table.
  380. */
  381. table = (char *) bridge->gatt_table_real;
  382. table_end = table + ((PAGE_SIZE * (1 << page_order)) - 1);
  383. for (page = virt_to_page(table); page <= virt_to_page(table_end); page++)
  384. ClearPageReserved(page);
  385. free_pages((unsigned long) bridge->gatt_table_real, page_order);
  386. return 0;
  387. }
  388. void null_cache_flush(void)
  389. {
  390. mb();
  391. }
  392. /* Setup function */
  393. static const struct aper_size_info_32 uninorth_sizes[] =
  394. {
  395. {256, 65536, 6, 64},
  396. {128, 32768, 5, 32},
  397. {64, 16384, 4, 16},
  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[] =
  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 = ARRAY_SIZE(uninorth_sizes),
  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 = ARRAY_SIZE(u3_sizes),
  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: " DEFAULT_APERTURE_STRING "M");
  610. MODULE_AUTHOR("Ben Herrenschmidt & Paul Mackerras");
  611. MODULE_LICENSE("GPL");