Commit | Line | Data |
---|---|---|
0cd33762 TL |
1 | # include "../h/param.h" |
2 | #include "../h/uba.h" | |
3 | # include "../h/map.h" | |
4 | ||
5 | int uballoc(baddr,bcnt,bdpflg) | |
6 | char bdpflg ; | |
7 | char * baddr ; | |
8 | unsigned short bcnt; | |
9 | { | |
10 | /* | |
11 | * Allocate as many contiguous UBA mapping registers | |
12 | * as are necessary to do transfer of 'bcnt' bytes | |
13 | * to/from location 'baddr'. | |
14 | * Wait for enough map registers. | |
15 | * 'bdpflg' is non-zero if a "buffered data path" (BDP) is | |
16 | * to be used, else 0 -> use direct data path (DDP) . | |
17 | * Return | |
18 | * | |
19 | * |31 - - 28|27 - - 18|17 - - - 9|8 - - 0| | |
20 | * | | | | | | |
21 | * | BDP | no. | start | byte | | |
22 | * | no. | mapping | map | offset| | |
23 | * | | reg's | reg. no. | | | |
24 | * | | | | | | |
25 | * | |
26 | */ | |
27 | ||
28 | register regnum , nmreg , bdp , pfn , j ; | |
29 | ||
30 | /* calculate no. of mapping reg's required */ | |
31 | nmreg = btoc(bcnt) + 2; | |
32 | pfn = ((int)baddr>>9) & 0xfff ; /* start page frame no. */ | |
33 | ||
34 | spl6() ; | |
35 | while ((regnum = malloc(ubamap,nmreg) - 1) < 0) { | |
36 | /* wait for no. of mapping reg's requested */ | |
37 | umrwant++ ; | |
38 | sleep(ubamap,PSWP) ; | |
39 | } | |
40 | if (bdpflg) /* buffered data path BDP 1-15 */ | |
41 | while ( (bdp=malloc(bdpmap,1)) == NULL) | |
42 | { | |
43 | bdpwant++; | |
44 | sleep(bdpmap, PSWP); | |
45 | } | |
46 | else { /* BDP 0 = DDP */ | |
47 | bdp = 0 ; | |
48 | } | |
49 | ||
50 | spl0() ; | |
51 | ||
52 | j = (bdp<<28) | (nmreg<<18) | (regnum<<9) | ((int)baddr & 0x01ff) ; | |
53 | pfn |= (MRV | (bdp<<21)) ; /* map reg entry */ | |
54 | ||
55 | if (bdp && ((int)baddr & 01)) pfn |= BO ; /* byte offset */ | |
56 | while (--nmreg) /* fill the memory mapping reg's */ | |
57 | ((struct uba_regs *)UBA0)->uba_map[regnum++] = pfn++ ; | |
58 | ((struct uba_regs *)UBA0)->uba_map[regnum] = 0 ; /* last entry is invalid */ | |
59 | ||
60 | return(j) ; | |
61 | } | |
62 | ||
63 | /* */ | |
64 | ||
65 | ubafree(mr) | |
66 | int mr ; | |
67 | { | |
68 | /* | |
69 | * Free UBA memory mapping reg's and a BDP no.. | |
70 | * mr : | |
71 | * bits 0 - 3 : bdp no. | |
72 | * 4 - 15 : start map reg. no. | |
73 | * 16 - 31 : no. of mapping reg's | |
74 | * | |
75 | */ | |
76 | ||
77 | register bdp , nmreg , regnum ; | |
78 | ||
79 | spl6(); | |
80 | bdp = (mr>>28) & 0x0f ; /* BDP no. */ | |
81 | if (bdp) | |
82 | { | |
83 | ((struct uba_regs *)UBA0)->uba_dpr[bdp] |= BNE ; /* purge */ | |
84 | mfree(bdpmap, 1, bdp); | |
85 | if (bdpwant) { | |
86 | bdpwant = 0; | |
87 | wakeup(bdpmap); | |
88 | } | |
89 | } | |
90 | ||
91 | nmreg = (mr>>18) & 0x3ff ; /* no. of mapping reg's */ | |
92 | regnum = (mr>>9) & 0x1ff ; /* 1st map reg. no. */ | |
93 | ||
94 | /* free mapping reg's */ | |
95 | mfree(ubamap,nmreg,regnum+1) ; | |
96 | if (umrwant) { | |
97 | umrwant = 0; | |
98 | wakeup(ubamap); | |
99 | } | |
100 | spl0() ; | |
101 | } | |
102 | ||
103 | ubainit() | |
104 | { | |
105 | mfree(ubamap, 496, 1); | |
106 | mfree(bdpmap, 15, 1); | |
107 | } |